[PYTHON] (Note) Template file search order in Django

Completely note.

Template search order example


django.template.loaders.filesystem.Loader: /Users/01013548/repositories/evolve/django_training/mysite/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/01013548/.pyenv/versions/3.5.2/lib/python3.5/site-packages/django/contrib/admin/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/01013548/.pyenv/versions/3.5.2/lib/python3.5/site-packages/django/contrib/auth/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/01013548/repositories/evolve/django_training/mysite/myapp/templates/index.html (Source does not exist)

As a search destination

  1. Inside the template directory directly under the Django project (mysite)
  2. The path to the python library and so on (well, don't you use this too much ... I can't see the purpose)
  3. In the template of the application (myapp) in the Django project

For 1, os.path.join (BASE_DIR,'templates') in TEMPLATE.DIRS inside setting.py Since it is specified, it seems that it is out.

As for 2 and 3, it seems that they can be searched because TEMPLATES.APP_DIRS inside setting.py is set to True. (False no longer searches)

Recommended Posts

(Note) Template file search order in Django
(Note) Django in Vagrant environment
Show Django ManyToManyField in Template
Use jinja2 template in excel file
Django note 4
Django Note 5
Django search
Django Note 1
Django note 3
Django note 2
Django HTML Template # 2
Models in Django
Django Template notes
Django HTML template
Django Template Tips
Django template reads Makdown and reStructuredText written in an external file as HTML
[Linux] File search
Specify the view URL in your Django template
Standard .py file used in Python trials (template)-2020
Do an ambiguous search for mysql in Django
Forms in Django
DJango Note: From the beginning (creating a view from a template)
How to use template engine in pyramid 1 file application
Django Middleware Execution Order
[Note] File reading ~ Python ~
File processing in Python
File operations in Python
Model changes in Django
File upload with django
Linear search in Python
Django Girls Tutorial Note
Binary search in Python (binary search)
Natural order in python
Set the DateTime type output format in your Django template
How to check ORM behavior in one file with django
Errors that often occur in django Part 1 About template.exceptions.TemplateDoesNotExist (Note)
[Note] Import of a file in the parent directory in Python
Google search for the last line of the file in Python
Command to list all files in order of file name