Search code examples
djangodjango-authentication

django authentication package: 'auth' not registered as a namespace


I'm trying to build a simple website with user authentication based on this tutorial, but I'm running into the above error. As per the instructions I set a url as folllows:

url('^accounts/', include('django.contrib.auth.urls'))

I got this error in response: 'auth' is not a registered namespace So I tried to register a namespace as the tutorial repo shows:

url('^accounts/', include('django.contrib.auth.urls', namespace="auth")),

then I get the error : Specifying a namespace in include() without providing an app_name

I realised that the tutorial is using django 1.8.3, but I'm on 2.0. The issue is resolved when I switch to the same django version in virtualenv, but I'm now having to a change a number of other things across the project to keep it from breaking. Any way to fix without require django 1.8? Thanks.


Solution

  • The URL routing syntax has been changed in Django 2.0, maybe try doing:

    from django.urls import path
    path('accounts/', include('django.contrib.auth.urls')),