Django是否附带用于Django.contrib.auth模块的身份验证模板?

2024-04-28 23:05:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我在tests目录下找到了一些,但我不确定它们是否正确。

我所说的身份验证模板是指login.htmpassword_reset.htm

一些模板可以在:http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/找到


Tags: 目录com身份验证模板httpauthenticationwithwordpress
3条回答

可以在django.contrib.admin.templates.registration使用身份验证模板:

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管理员的外观和感觉,所以我建议定制它。

不,它会在模板文件夹中的“注册”目录中查找这些模板。

从文档中:

It's your responsibility to provide the login form in a template called registration/login.html by default.

Password Reset Optional arguments:

template_name: The full name of a template to use for displaying the password reset form. This will default to registration/password_reset_form.html if not supplied.

文件:loginpassword_reset

虽然Django documentation显式声明“Django没有为身份验证视图提供默认模板”,但我发现使用管理模板很简单。只需启用管理应用程序,然后将其添加到url.py:

url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'admin/login.html'}),
url('^accounts/', include('django.contrib.auth.urls')),

所有的认证url现在都可以工作了,尽管有Django管理员的外观。

相关问题 更多 >