1

I'm upgrading one of my projects to Django 1.8.3 and one of the few challenges is that my custom registration templates are no longer being access by Django.

Base on this: https://stackoverflow.com/a/19226149/3390630 I have my custom registration files inside my appname/templates/registration folder.

As Django made some major changes to the way the templates are now being accessed, Django 1.8 is no longer looking for my custom registration files and I get this error:

NoReverseMatch at /resetpassword/
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

I tried to add the following loaders to the TEMPLATES settings but no luck.

'loaders': [
            'django.template.loaders.app_directories.Loader',
            'django.template.loaders.filesystem.Loader',
        ]

I'm also using custom urls for login, logout, password reset etc.

My URLs

...
url(r'^resetpassword/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
url(r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', name='password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete'),
...

Any suggestions how to make Django look inside my custom folder again?

Community
  • 1
  • 1
WayBehind
  • 1,607
  • 3
  • 39
  • 58

3 Answers3

3

I struggled with this problem too. The solution suggested : changing 'APP_DIRS': False, is not good, as it'll stop loading any templates of apps which are in your virtual environment.

Solution is to Keep your registration templates inside templates folder inside root of your project; not inside any app: appname/templates/.

For this you'll have to add:

'DIRS': [os.path.join(BASE_DIR, 'templates')], 

in templates definition in settings file.

Second problem you may face that still after doing this, for forgot password template it'll load Django admin template, for that: put 'registration' before 'django.contrib.admin' in INSTALLED_APPS in settings file.

INSTALLED_APPS = (
    'registration',
    'django.contrib.admin',
varnothing
  • 1,269
  • 1
  • 17
  • 30
  • Order of INSTALLED_APPS items was issue for me. Thanks. It's counter-intuitive that that prior items take precedence over what follows - is the rationale explained anywhere in django docs? – michela Feb 28 '16 at 02:47
  • It has to something with the order django read app's template directory. I am sorry; couldn't find any documentation. – varnothing Feb 29 '16 at 14:10
1

In Django, reverse() method is used to reverse a name, a read friendly name, to match a URL pattern. Here, your regex '^resetpassword/$' doesn't have a name to be reversed. Add the parameter name='password_reset_done'to your url. Something like,

    url(r'^resetpassword/$', 'django.contrib.auth.views.password_reset', {'post_reset_redirect': reverse_lazy('auth_password_reset_done'), 
name='password_reset_done'), #Where 'auth_password_reset_done' is where you want to redirect post form submission on the reset page.

Also, you need to re-format your URL configurations as it lacks a few essential parameters, to something like this,

url(r'^password/reset/$',
   auth_views.password_reset,
   {'post_reset_redirect': reverse_lazy('auth_password_reset_done'), 
   'template_name': 'registration/password_reset.html'},
   name='auth_password_reset'),

url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
   auth_views.password_reset_confirm,
   {'post_reset_redirect': reverse_lazy('auth_password_reset_complete'),
   'template_name' : 'registration/reset_confirm.html'},
   name='auth_password_reset_confirm'),

url(r'^password/reset/complete/$',
   auth_views.password_reset_complete,
   {'post_reset_redirect': reverse_lazy('auth_password_reset_complete'), 
    'template_name' : 'reset_complete'},
   name='auth_password_reset_complete'),

url(r'^password/reset/done/$',
   auth_views.password_reset_done,
   {'template_name': 'registration/reset_done.html'},
   name='auth_password_reset_done'),
Sentient07
  • 1,270
  • 1
  • 16
  • 24
  • Thank you for the suggestion. I have added the missing `name='password_reset_done'` but still get the same error. Any other suggestions? – WayBehind Jul 13 '15 at 01:20
  • BTW this is what Django has inside the `auth` URLs `url(r'^password_reset/$', views.password_reset, name='password_reset'),` – WayBehind Jul 13 '15 at 01:31
  • 1
    @WayBehind : This is your problem right , http://stackoverflow.com/questions/20307473/django-built-in-password-reset-views ? – Sentient07 Jul 13 '15 at 01:49
  • Anyway, if you want to reverse a "String" a valid URL pattern mapping to a view must have that "String" as name, else there will be NoReverseMatch error – Sentient07 Jul 13 '15 at 01:52
  • Thank you for the link. Unfortunately, still no luck. I have updated my OP wit the four URLs I'm using and getting error. – WayBehind Jul 13 '15 at 02:06
  • @WayBehind Do you still get the exact same error ? Can you paste the traceback ? – Sentient07 Jul 13 '15 at 02:10
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83087/discussion-between-sentient07-and-waybehind). – Sentient07 Jul 13 '15 at 02:23
0

This is what I had to do in order to get the custom Registration folder going.

  1. Moved the URLs from my app/urls.py to the project/urls.py
  2. Change TEMPLATES in settings.py to 'APP_DIRS': False,

Hope this may be helpful to others and thanks to @Sentient07 for pointing me in the right direction!

WayBehind
  • 1,607
  • 3
  • 39
  • 58