在Django中覆盖外部应用程序的模板 [英] Override templates of external app in Django

查看:112
本文介绍了在Django中覆盖外部应用程序的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想覆盖外部应用的模板( allauth ,安装在网站包中)。不幸的是没有任何建议,我读了工作。
我将以下内容添加到我的 settings.py 中:

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'))

并复制所有模板(此内容)到 my_project_dir / templates / allauth 。但是当我重新启动服务器并重新加载页面时,我只能从站点包中的原始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?

推荐答案

我倾向于弄清楚发生了什么(使用 DEBUG 设置为 True ),是一个视图渲染一个不存在的模板,并查看位置列表Django尝试加载模板(这将被包含在错误页面输出中)。

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).

想要渲染的视图有哪些模板?如果他们试图渲染 allauth / foo.html ,那么你需要添加 my_project_dir / templates 您的 TEMPLATE_DIRS 设置,而不是 my_project_dir / templates / allauth

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.

这篇关于在Django中覆盖外部应用程序的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆