Pelican - How can I render html pages instead of markup? - python

I'm redoing my Flask site in Pelican as I intend to start blogging. I have html files already for some specific pages (i.e. contact, books, etc) that use bootstrap cards and other features that are not possible in markdown (as far as I know).
How can I render these in the build cycle. There has to be a config variable for that? I found TEMPLATE_PAGES but it didn't seem to work. This has to be possible, right?

I was trying to do the same thing as you and finally found the relevant documentation (you can find it here where it defines the variable DIRECT_TEMPLATES):
DIRECT_TEMPLATES = ['index', 'categories', 'authors', 'archives']
List of templates that are used directly to render content. Typically direct templates are used to generate index pages for collections of content (e.g., tags and category index pages). If the tag and category collections are not needed, set DIRECT_TEMPLATES = ['index', 'archives']
For example, let's say you have a file my_file.html in your templates directory. If you want to render it like other templates files in your theme instead of using only Markdown, you could append an item to the list in the variable DIRECT_TEMPLATES that you will have to define in your configuration file (it is pelicanconf.py by default). The result should look similar to this:
DIRECT_TEMPLATES = [
'index', 'categories', 'authors', 'archives', # (default)
'my_file' # other HTML template to render
]
By proceeding this way, my_file.html would be rendered as any other HTML file with Jinja2 syntax and all the good stuff you want to use.
I know this comes late but hopefully someone (maybe still you!) will benefit from this answer. It is definitely a very well hidden feature for sure...

from their official documentation
http://docs.getpelican.com/en/stable/content.html#writing-content
Pelican can also process HTML files ending in .html and .htm. Pelican
interprets the HTML in a very straightforward manner, reading metadata
from meta tags, the title from the title tag, and the body out from
the body tag:

Related

Best way to store web page content in database using Django and a single template for web pages

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.

How can I override the default template used by a page or article in pelican?

I would like to know how can I use a different template for a page or article in pelican?
So far, it seems that for articles is using article.html and for pages page.html.
You can set the output filename by using the Template metadata in your individual files. This will override the default that you set in your configuration file.
For Markdown you would include this in your header:
Template: template_name
This is discussed in the FAQ on the pelican website.
Pelican looks for templates in whatever directory you've specified as THEME in your pelicanconf.py. If you just want to change what the output looks like, you can modify article.html or page.html in that directory (the default is themes/notmyidea relative to wherever pelican is installed). See how to create themes for Pelican for more.
If you actually want to change the name of the file that Pelican looks for to generate the articles or pages, that's a bit trickier. I don't know of any setting that allows this to be altered, but the relevant bit of the Pelican source appears to be here, so if you really want this you could consider subclassing Content yourself of just changing the relevant lines in your copy of Pelican.

Django return .html file directly without parsing for template tags at all

I'm writing a single view Javascript application with a Django backend that only needs to return the initial index.html and all other templates come from a CDN. My problem is that this first index.html file is parsing out some of my "{{}}" handlebars which I wanted to leave for the JS library to interpret.
I DO NOT want to use 'verbatim' or 'raw' or any additional tags because I don't want any django specific stuff in my static template files.
A possible alternative answer to this would be desmonstrating how to to make your inital index HTML response also come from the CDN but I didn't think that was possible.
If you don't want to render a template, simply don't render it. Django won't render anything unless you specifically call template.render or one of the shortcuts.
If you just want to return an HTML file, you could just open it as a normal file, read it, then return the content as the response.
Alternatively, as suggested in the comment, you can serve it as a static file.

Google App Engine(Python) - site fragments - composite view

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"

Find untranslated strings in HTML templates

Is there way to find untranslated strings in the HTML templates of my Django application i.e. blocks of text that are not wrapped in trans and blocktrans tags.
Since we have many templates, it would be a very time-consuming process to go through them manually and check but if there isn't an option, I guess it has to be done the long and tedious way.
Thanks
Found this recently, but have not tried it yet.
Doc: http://www.technomancy.org/python/django-template-i18n-lint/
Code: https://github.com/rory/django-template-i18n-lint
Looks like it hasn't been updated in a year but it might provide a good starting spot.
You can use the builtin template parser to parse your templates, and recurse into all tags that are not instances of BlockTransTag

Categories

Resources