【发布时间】:2016-04-13 21:23:30
【问题描述】:
我使用的是Django(v1.8.12)的默认认证系统,但是我想创建自己的模板(实际上根据文档django.contrib.auth不提供任何模板)。
然后我在我的应用程序“mainApp”的“模板”文件夹中添加了文件夹“注册”。根据文档,这是正确的位置,名为“registration”的文件夹。
我还创建了模板“login.html”,并且该模板在定义的 url '...account/login' 处正确加载。
问题出在其他模板上:
- logged_out.html
- password_change_done.html
- password_change_form.html
- password_reset_complete.html
- password_reset_confirm.html
- password_reset_done.html
- password_reset_email.html
- password_reset_form.html
以前的模板是从“管理”应用程序而不是我的应用程序加载的。
我如何告诉 Django 应该加载我的“注册”模板而不是管理应用程序中定义的模板?
我的项目 url.py 是
urlpatterns = [
url(r'^', include('mainApp.urls', namespace="mainApp")),
url(r'^admin/', include(admin.site.urls)),
url(r'^account/', include('django.contrib.auth.urls')),
]
我的模板设置是默认设置
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'debug': True,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
【问题讨论】:
-
好的。我刚刚在模板设置中尝试过这个,现在正在使用
'DIRS': ['mainApp/templates'],。无论如何,我愿意接受一个更通用的解决方案,你可以给我:)。 -
更新以前的解决方案在生产中不起作用(我的意思是在服务器中)
标签: django templates authentication