Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django template file extension preference

This Django ticket says that they will not add a default Django template file extension. What file extension do you use?

like image 459
Spencer Avatar asked Jan 09 '10 23:01

Spencer


People also ask

Which of the following is the file extension for a Django template file?

html. djt). Without a differentiated extension, you need to open a file in order to know it's a django template and not a regular (e.g. HTML) file.

Which option does Django templates accept?

DjangoTemplates engines accept the following OPTIONS : 'autoescape' : a boolean that controls whether HTML autoescaping is enabled. It defaults to True . Only set it to False if you're rendering non-HTML templates!

What is Jinja format in Django?

Jinja is similar to the Django template engine but provides Python-like expressions while ensuring that the templates are evaluated in a sandbox. It is a text-based template language and thus can be used to generate any markup as well as source code. Jinja.

Does Django use jinja2?

Django sets Jinja with two default behaviors, one for when DEBUG=True -- a common setting in development -- and the other for when DEBUG=False -- a common setting in production. If DEBUG=True and an invalid variable is set in a Jinja template, Jinja uses the jinja2.


2 Answers

I honestly believe we need a standard extension for django template files. A template is NOT valid CSS/HTML/XML or anything else.

Nick Presta wrote:

  1. You already know the files are templates because they should be in a template directory
  2. You don't want to have to open up files to see what they are (HTML, CSS, XML, etc). You would have to do this with a generic extension like .djt.

Point #2 can also be used in favor of a default extension or a mix (like .html.djt). Without a differentiated extension, you need to open a file in order to know it's a django template and not a regular (e.g. HTML) file.

And point #1 is just plain wrong, considering that they are not always in a template directory.

like image 81
airstrike Avatar answered Sep 22 '22 05:09

airstrike


Ruby on Rails uses .html.erb for erb templates, something similar will work for Django too.

like image 42
adamse Avatar answered Sep 19 '22 05:09

adamse