Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 380
Shiny_and_Chrome Avatar asked Dec 06 '17 04:12

Shiny_and_Chrome


1 Answers

for Django 2.0 syntax should be like this

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

    <li><a href="{% url 'auth:login' %}">Login</a></li>#do not use this in any template
    <li><a href="{% url 'login' %}">Login</a></li>#use this in your template
like image 77
Parag Jain Avatar answered Sep 21 '22 05:09

Parag Jain