I'm trying to investigate if I can use Pelican to generate my site and having trouble seeing how to present two different lists of articles, each rendered in their own template.
My site has blog pieces, feature articles, and white papers. The index page for each of these needs to be rendered in a different style.
After a little playing around, it appears to me that I would probably need to have a category for each article-type. Is it possible to tell the engine to render each category list using a different template.
Alternatively, and perhaps better for increased flexibility, is it possible to create a page that loops through a category and i control the display of the article list? I could then solve the problem by creating a page of my own for each category. Does a page have access to the pelican context (i.e. the catalog of content built by the generators' generate_context methods)
Related
Apologies for not having any specific broken code here. I already know that what I would try won't work from a different question here, and I have a vague idea of something that might work but is likely not the best way to do it.
I'm building a website for a photographer, so it's important that I'm loading the best looking photos that the user is capable of seeing. The starting file size for the images is a few MB, but the model uses Pillow to save down-scaled copies. There are times when I want a full-screen image at high resolution, but I want to serve a smaller image if the user is on mobile, for example.
What I would have done was load the images from CSS background-image with media queries, but I understand that I can't use template tags in CSS.
My next guess would be to build two separate versions of each template and have the views render a different template based on the user-agent of the request, but that strikes me as probably not a great solution to put that much trust in the request headers, and the functionality could break as easily as a new browser release. There's a better way, right?
Why not CSS? - In this case, the images are dynamic content. The photographer doesn't know web development and I'm not going to update the site for him every time he adds or removes images or blog posts, etc, so the site is a lite CMS. He can freely add or remove images from galleries, etc. The django view/template then find and serve the images from the query set. Instead of referring to specific images and their specific smaller versions, I'm asking the server to serve whatever images currently belong to a specific queryset in the database, and serve either the smaller or larger versions of the images, and to do so with the explicit goal of not having the user download resolution that they can't see.
I'm building a web site and the bulk of the content will be the same general type and layout on the page. I'm going to use a single template to handle each post and the actual content will be stored in a database.
The content will just be html paragraphs, headers, sub headers, different lists, quotes, code blocks, etc.
Web pages will typically be the same or at least similar. All html components should follow the same guidelines to make sure everything looks and feels the same. Currently I'll be the only author, but in the future I plan to incorporate other authors as well.
At first I thought, just copy and paste this html content into a textfield in the database and I can add new posts/articles on the admin site.
Then I thought, maybe use a textfield and copy and paste json of a list of ['type': , 'content': ]. and then I can have the single template page iterate over this list and display the content based on the 'type'. My idea here is that it would shorten the data I have to add to the database by stripping the html tags out of the equation.
Considering I hope to have future authors as well, just curious of some ideas on how I can accomplish this to make it easy for myself to post new content.
That sounds pretty much exactly like the example of this fantastic tutorial by Miguel Grinberg. He sets up a flask environment to be used as his personal blog. With user log in and everything you would need.
I have a few longer articles in my blog and would like to split them somehow into multiple pages, e.g. through inserting manual page breaks.
Is there any plugin for this or any default template mechanism?
There are at least two related plugins in the Pelican Plugins repository:
Series
Sub-parts
I imagine you will find that one — or both in conjunction — will suit your needs.
I'm looking to add search capability into an existing entirely static website. Likely, the new search functionality itself would need to be dynamic, as the search index would need to be updated periodically (as people make changes to the static content), and the search results will need to be dynamically produced when a user interacts with it. I'd hope to add this functionality using Python, as that's my preferred language, though am open to ideas.
The Google Web Search API won't work in this case because the content being indexed is on a private network. Django haystack won't work for this case, as that requires that the content be stored in Django models. A tool called mnoGoSearch might be an option, as I think it can spider a website like Google does, but I'm not sure how active that project is anymore; the project site seems a bit dated.
I'm curious about using tools like Solr, ElasticSearch, or Whoosh, though I believe that those tools are only the indexing engine and don't handle the parsing of search content. Does anyone have any recommendations as to how one may index static html content for retrieving as a set of search results? Thanks for reading and for any feedback you have.
With Solr, you would write code that retrieves content to be indexed, parses out the target portions from the each item then sends it to Solr for indexing.
You would then interact with Solr for search, and have it return either the entire indexed document an ID or some other identifying information about the original indexed content, using that to display results to the user.
Is there a way to build three or four parts of a site (three or four html templates) and then render some of them or all of them together in GAE python? I know I can load and render one specific html django template but I want to build templates for different parts of the site in different files and then compose them together depending on the situation.
A good example would be that I want pretty much the same menu, header, footer in most of my web application pages but I want to switch a specific part of the content.
So I would like to have one file and template that deals with lets say classes and another that deals with students, so the general look of the site (main.html) stays the same but the way I display and handle the information about students or classes is completely different. I basically want to plant a bunch of page specific html into a generic template.
Thanks for any help on this. :)
I am not sure what is the correct technical term for what I'm looking for(I tried searching). => I think they call it composite view or site fragments in the Zend framework.
You should use template inheritance in Django. Have a look at this tutorial for a start.
EDIT The official Django Book section on Template Inheritance also demonstrates how different 'fragments' e.g. a footer, or a nav bar, may be stored in different template files and brought together via inclusion and inheritance.
This site shows how one template can inherit from another, as when a site section template extends a basic layout template, with the code, for example,
{% extends "base.html" %}
It also shows how using template inclusion one may, for example, add different pieces to a larger template like pieces in a puzzle. For example, a navigation fragment may be added to a layout file with the phrase
{% include "nav.html" %}
As noted in the comments by #Nick Johnson: extends is more compact and can make the use of multiple file fragments unnecessary. Only include as last resort, if extends fails you.
EDIT See also my answer to a question on "How to cut large HTML file into multiple HTML files"