How can one include a file in a django template like {% include %} would, but without parsing the file's contents ?
I am aware of {% ssi %} but that last one would not accept relative paths and throws '[Didn't have permission to include file]' at me.
EDIT: this is NOT a duplicate of How can I tell Django templates not to parse a block containing code that looks like template tags? . As I commented here, I need a directive to include a whole file, not a directive to ignore a block inside a template.
Note: I'm trying to include angularJs templates which are in the project's directory, but the syntax conflicts with Django template
If you don't want to have to modify the files you're including, it looks as if the only way to do this is with a custom template tag.
Fortunately, it looks as if someone else has already posted one called include_raw on djangosnippets.org, although it was written for an older version of Django, so you'll have to make some modifications along the lines of those mentioned in one of the comments below the snippet.
Related
In my Flask application, I have one html file that holds some html and some js that semantically belongs together and cannot be used separately in a sensible way. I include this file in 2 of my html templates by using Jinja's {%include ... %}.
Now my first approach was to put this file in my templates folder. However, I never call render_template on this file, so it seems unapt to store it in that directory.
Another approach would be to put it into the static folder, since its content is indeed static. But then I don't know how to tell Jinja to look for it in a different directory, since all the files using Jinja are in the templates folder.
Is there a way to accomplish this with Jinja, or is there a better approach altogether?
You're over-thinking this. If it's included by Jinja, then it's a template file and belongs in the templates directory.
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.
I am using multiple language in mezzanine and it is working fine with its own core templates.But I try to use it in my own templates then it is not working.
I have use all things in proper steps. I have locale folder in which django.po consists of all text which I can translate and there encoded django.mo file.
Buy when I choose other then English Lang. in my browser it does not translate my templates text but change the text of core templates.
I don't know why it does not translate my templates data Because if there are any kind of errors then it must not translate core templates but it does.
Please help me to sort out my problem , any suggestion would be appreciated.
Thanks.
Does your .po file contain the word "fuzzy"? If so, you might want to read the following article: http://blog.e-shell.org/124, as mentioned in this previous SO question: Django missing translation of some strings. Any idea why?
If that is not the cause of your issue, are you sure you are using the internationalisation template tags appropriately?
First of all, ensure you are loading the relevant template tags at the top of each of your templates:
{% load i18n %}
Then, for any text you want to make translatable:
{% trans "Insert your text here" %}
See also: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#internationalization-in-template-code and https://docs.djangoproject.com/en/dev/topics/i18n/translation/#implementation-notes.
Everytime I add a particular object to my database (this only affects one particular app on my site), I get the TemplateSyntaxError 'markup_tags' is not a valid tag library.
Specifically, it cannot load this: {% load markup_tags %}. But this is strange because when I open a Django shell and import markup all is fine.
This question has been asked before on StackOverflow here: Django markup templatetags error
However, I don't understand why this is happening and I don't really understand how to fix it. They said render_to_response the template. But I'm not sure exactly how I would do this from the shell (Django noob here).
So the problem was that I was actually not properly importing the module into into my project that contained markup_tags. While the library was available in my environment, in my settings.py I did not properly reference it. Dumb mistake, but might help someone else.
Consider trying {% load markup %} in your template.
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"