非常简单的问题。在视图上方使用login_required
装饰器时,身份验证系统会使用registration/login.html
中的模板将我重定向到settings.py中的LOGIN_URL
中定义的任何URL。在Django 1.5中更改登录表单的默认模板
问题:如何为我的登录表单定义不同的模板名称(我不想使用默认值)?
非常简单的问题。在视图上方使用login_required
装饰器时,身份验证系统会使用registration/login.html
中的模板将我重定向到settings.py中的LOGIN_URL
中定义的任何URL。在Django 1.5中更改登录表单的默认模板
问题:如何为我的登录表单定义不同的模板名称(我不想使用默认值)?
如果你不想调用模板
registration/login.html
,您可以通过额外的参数传递template_name
参数在URLconf视图。例如,该行的URLconf会使用myapp/login.html
代替:
(r'^accounts/login/$',
'django.contrib.auth.views.login',
{'template_name': 'myapp/login.html'}),
---- Django的1.10 --------
我的设置更改template_dir模板来解决这个问题
setting.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},]
urls.py
url(r'^login/$', auth_views.login, {'template_name': 'registration/login.html'}, name='login'),
并将registration
文件目录放在templates
目录下!
btw我正在使用自定义登录 – KKlalala