Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best location to put templates in django project?

Tags:

django

What is the best location to put templates in django project?

like image 950
Vishal Avatar asked Nov 16 '09 06:11

Vishal


People also ask

Where should I put my templates in Django?

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.

How do I organize my Django templates?

There are two main ways to organize your template structure in Django: the default app-level way and a custom project-level approach.

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!

Is it template or templates in Django?

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.


2 Answers

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

like image 166
dlrust Avatar answered Sep 22 '22 14:09

dlrust


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)

like image 41
Dominic Rodger Avatar answered Sep 22 '22 14:09

Dominic Rodger