For a new project we’re writing documentation about the Django template system. We use Django for the documentation project itself too, so Django picks up all our example variables in the sample code and tries to render them. The only way we found to get around this is to use {% templatetag %}, but that makes our code really unreadable. Is there maybe a way to make Django ignore all template variables in a specific section?
For a new project we’re writing documentation about the Django template system. We use
Share
Due to limitations in the Django template lexer (like being a kludgy hack), this is impossible. However, if you are willing to put your example code in separate files, you can use the
ssitag:And it won’t parse the file, just include it verbatim. However, this also has limitations in that you can’t use variables in the include path (i.e. if you move template locations, you have to rewrite or at least find-and-replace your template files), and you have to put the include path (i.e.
/path/to/my/code/examples) in theALLOWED_INCLUDE_ROOTSsetting in yoursettings.py. (See http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ssi.)