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

4

10

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/

Dustin answered 11/7, 2011 at 6:14 Comment(0)
P
6

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

Prynne answered 11/7, 2011 at 6:26 Comment(4)
I vaguely remember that Django had these templates somewhere online on the Django site but I can't dig it up. There were templates for all the auth views.Dustin
That's interesting, I've actually never heard about or seen these. Are you sure it was on the Django site, and that you're not remembering the forms themselves?Prynne
I found it. They were here: devdoodles.wordpress.com/2009/02/16/…. The post is old but most of the forms work once you've added the CSRF token.Dustin
Django 2.0 does ship with built in templates for password reset. In fact, I am struggling to override them now.Herrah
J
19

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.

Jerilynjeritah answered 19/5, 2013 at 0:45 Comment(2)
/login result in Unknown template variable <Variable: u'title'> title - Django 1.9.2Hydrocellulose
Support for string view arguments in url() has been removed with Django 1.10. Use from import django.contrib.auth.views import login and url(r'^accounts/login/$', login, ... instead.Client
E
12

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.

Eastereasterday answered 11/7, 2011 at 14:40 Comment(2)
How do you go about adding these to the project?Hydrocellulose
Just copy them to your template dirEastereasterday
P
6

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

Prynne answered 11/7, 2011 at 6:26 Comment(4)
I vaguely remember that Django had these templates somewhere online on the Django site but I can't dig it up. There were templates for all the auth views.Dustin
That's interesting, I've actually never heard about or seen these. Are you sure it was on the Django site, and that you're not remembering the forms themselves?Prynne
I found it. They were here: devdoodles.wordpress.com/2009/02/16/…. The post is old but most of the forms work once you've added the CSRF token.Dustin
Django 2.0 does ship with built in templates for password reset. In fact, I am struggling to override them now.Herrah
K
6

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.

Kinky answered 8/8, 2011 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.