I want to override the templates of an external app (allauth, installed in site packages). Unfortunately no advice i read worked.
I added the following to my settings.py
:
PROJECT_ROOT = os.path.normpath(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, 'templates', 'allauth'))
and copied all templates (this content) to my_project_dir/templates/allauth
. But when I restart the server and reload the page I only get the rendered templates from the original allauth app in site packages, not mine custom templates. Any hints?
You can either put template overrides in your project's templates directory or in an application's templates directory. If you have app and project templates directories that both contain overrides, the default Django template loader will try to load the template from the project-level directory first.
The include tag allows you include a template inside the current template. This is useful when you have a block of content that are the same for many pages.
{% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.
Check the INSTALLED_APPS
order, the first template matched will be rendered.
With this in mind you can just add the template under the same path in a custom app.
The way I tend to figure out what's going on (with DEBUG
set to True
), is to have a view render a template that didn't exist, and look at the list of locations Django tried to load templates from (which will be included in the error page output).
What templates are the views trying to render? If they're trying to render allauth/foo.html
, then you'll want to add my_project_dir/templates
to your TEMPLATE_DIRS
setting, not my_project_dir/templates/allauth
.
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