Django 1.6 and django-registration: built-in authentication views not picked up

痞子三分冷 提交于 2019-12-02 20:36:39
Jannis

The reason for this error is that the django.contrib.auth.views use different url names than the registration.auth_urls ones. To patch this problem, override the default urls until django-registration gets updated for django 1.6, and use the same names as Django.

from django.contrib.auth import views as auth_views


urlpatterns = patterns('',

      #override the default urls
      url(r'^password/change/$',
                    auth_views.password_change,
                    name='password_change'),
      url(r'^password/change/done/$',
                    auth_views.password_change_done,
                    name='password_change_done'),
      url(r'^password/reset/$',
                    auth_views.password_reset,
                    name='password_reset'),
      url(r'^password/reset/done/$',
                    auth_views.password_reset_done,
                    name='password_reset_done'),
      url(r'^password/reset/complete/$',
                    auth_views.password_reset_complete,
                    name='password_reset_complete'),
      url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
                    auth_views.password_reset_confirm,
                    name='password_reset_confirm'),

      #and now add the registration urls
      url(r'', include('registration.backends.default.urls')),
)

Here is what I used:

url(r'', include('registration.backends.default.urls')),
url(r'', include('django.contrib.auth.urls')),

Django contrib now includes the missing urls

Background

This issue seems to have cropped again for django-registration==1.0 and Django==1.6 and is documented here on the official django-registration pull request. I used the solution provided by @Jay but it didn't work specifically for the password reset part. I ended up with this error:

Error

password_reset_confirm() got an unexpected keyword argument 'uidb36'

Solution

Instead I pulled from another django-registration repository (as mentioned in the official pull request above) by doing the following:

  1. pip uninstall django-registration
  2. pip install git+git://github.com/macropin/django-registration.git
  3. Modify the code for 'urls.py' as mentioned in the post by @Jay (thanks!)
  4. Remember this is a temporary solution until the official django-registration support is updated for Django 1.6
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!