开发者

Does Django ship with the authentication templates for use with the django.contrib.auth module? [duplicate]

This question already has answers here: Is there a built-in login template in Django? (6 answers) Closed 6 years ago.

I found some under the tests directory but I'm not sure if they are the right ones.

By authentication templates I mean login.htm, password_reset.htm, etc.

Some of th开发者_如何学编程e templates can be found at: http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/


While the Django documentation explicitly states that "Django provides no default template for the authentication views", I found that it is trivial to use the admin templates. Just enable the admin app, then add this to urls.py:

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

All of the authentication urls work now, albeit with the Django admin look-and-feel.


You can use the auth templates at 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

Those will have the look and feel of the Django Admin, so I would suggest to customize it.


No, it looks for those templates in a "registration" directory within your templates folder.

From the docs:

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.

Docs: login, password_reset


By copying the templates located in django.contrib.admin.templates.registration as mentioned by DZPM above and placing them into your own registration app's templates directory e.g. *your_proj_root/registration/templates/registration/*

IMPORTANT! If you are keeping the same exact filenames for your templates, you have to remember to make sure that your django.contrib.admin app line is placed below your registration app line; otherwise, it will use the django.contrib.admin's registration templates in preference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜