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

浪子不回头ぞ 提交于 2019-12-18 05:55:46

问题


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 the templates can be found at: http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/6646400/does-django-ship-with-the-authentication-templates-for-use-with-the-django-contr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!