What is the best location to put templates in django project?
To configure the Django template system, go to the settings.py file and update the DIRS to the path of the templates folder. Generally, the templates folder is created and kept in the sample directory where manage.py lives. This templates folder contains all the templates you will create in different Django Apps.
There are two main ways to organize your template structure in Django: the default app-level way and a custom project-level approach.
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!
Templates are the third and most important part of Django's MVT Structure. A template in Django is basically written in HTML, CSS, and Javascript in a . html file. Django framework efficiently handles and generates dynamically HTML web pages that are visible to the end-user.
Placed in <PROJECT>/<APP>/templates/<APP>/template.html
for app-specific templates to help with making the app reusable elsewhere.
For general "global" templates I put them in <PROJECT>/templates/template.html
From the Django book, chapter 4:
If you can’t think of an obvious place to put your templates, we recommend creating a templates directory within your Django project (i.e., within the mysite directory you created in Chapter 2, if you’ve been following along with our examples).
This is exactly what I do, and has worked great for me.
My directory structure looks something like this:
/media
for all my CSS/JS/images etc/templates
for my templates/projectname
for the main project code (i.e. the Python code)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With