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/

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382

4 Answers4

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.

Travis
  • 1,998
  • 1
  • 21
  • 36
  • `/login` result in `Unknown template variable title` - Django 1.9.2 – Rebs Feb 29 '16 at 06:06
  • Support for string view arguments in `url()` [has been removed with Django 1.10](https://docs.djangoproject.com/en/1.11/releases/1.10/#features-removed-in-1-10). Use `from import django.contrib.auth.views import login` and `url(r'^accounts/login/$', login, ...` instead. –  Jun 16 '17 at 09:59
11

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.

David Arcos
  • 5,957
  • 5
  • 30
  • 39
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

Ajoy
  • 1,838
  • 3
  • 30
  • 57
rolling stone
  • 12,668
  • 9
  • 45
  • 63
  • 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. – Mridang Agarwalla Jul 11 '11 at 06:29
  • 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? – rolling stone Jul 11 '11 at 06:42
  • I found it. They were here: http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/. The post is old but most of the forms work once you've added the CSRF token. – Mridang Agarwalla Jul 25 '11 at 09:16
  • 1
    Django 2.0 does ship with built in templates for password reset. In fact, I am struggling to override them now. – Kermit Mar 12 '18 at 23:25
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.

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167