7π
β
You can use templates in TEMPLATE_DIRS to either override templates coming from apps (by giving them the same name) or for templates that are relevant for more than one app (base.html comes to mind).
This works because of the order in which template loaders are set in TEMPLATE_LOADERS (filesystem before app_directories).
Itβs a good idea to organize your templates in the following way to avoid name collisions:
<project>/
<app1>/templates/<app1>/
foo.html
bar.html
<app2>/templates/<app2>/
foo.html
templates/
<app1>/
foo.html
base.html
xyzzy.html
π€user3850
0π
You also need to define this TEMPLATE_DIRS in order to override external modules templates.
If your template folder located as hop recommended in previous answer, you can define the TEMPLATE_DIRS in this manner, to have it more portable:
import os
cwd = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = cwd[:-9]
# other code comes here ...
TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, "templates"),
)
π€Kostanos
- [Django]-How can I rename an uploaded file on Django before sending it to amazon s3 bucket?
- [Django]-Django template: How can I regroup a list of dictionaries by a nested property of each dictionary?
Source:stackexchange.com