Django NoReverseMatch

Ich erstelle eine einfache Login-App in Django 1.6 (und Python 2.7) und bekomme am Anfang eine Fehlermeldung, die mich nicht weiter machen lässt.

Dies ist die URL der Site

from django.conf.urls import patterns, include, url
from django.contrib import admin
import login

admin.autodiscover()

urlpatterns = patterns('',
    url(r'^

Und das ist login / urls.py:

from django.conf.urls import patterns, url
from login import views

urlpatterns = patterns('',
    url(r'^

Dies ist Login / Ansichten, py

from django.shortcuts import render
from django.contrib.auth import authenticate

def auth(request):
    user = authenticate(username=request.POST['username'], password=request.POST['password'])
    if user is not None:
        # the password verified for the user
        if user.is_active:
            msg = "User is valid, active and authenticated"
        else:
            msg = "The password is valid, but the account has been disabled!"
    else:
        # the authentication system was unable to verify the username and password
        msg = "The username and password were incorrect."
    return render(request, 'login/authenticate.html', {'MESSAGE': msg})

def index(request):
    return render(request, 'login/login_form.html')

Ich habe ein Formular, das dies als Aktion hat:

{% url 'login:auth' %}

Und da ist das Problem, wenn ich versuche, die Seite zu laden, erhalte ich:

Reverse for 'auth' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$auth/']

Aber wenn ich das URL-Muster auf setze

url(r'', views.auth, name='auth')

es funktioniert gut, nur setzt es die Aktion als '/'.

Ich habe mich nach einer Antwort umgesehen und verstehe nicht, warum es nicht funktioniert.

Ich habe versucht, das Anmelde-URL-Muster in url (r '^ login / $9$#39;, include ('login.urls', namespace = 'login') zu ändern, und es hat sich nichts geändert.

, include('login.urls', namespace='login')), url(r'^admin/', include(admin.site.urls)), )

Und das ist login / urls.py:

from django.conf.urls import patterns, url
from login import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^auth/', views.auth, name='auth'),
)

Dies ist Login / Ansichten, py

from django.shortcuts import render
from django.contrib.auth import authenticate

def auth(request):
    user = authenticate(username=request.POST['username'], password=request.POST['password'])
    if user is not None:
        # the password verified for the user
        if user.is_active:
            msg = "User is valid, active and authenticated"
        else:
            msg = "The password is valid, but the account has been disabled!"
    else:
        # the authentication system was unable to verify the username and password
        msg = "The username and password were incorrect."
    return render(request, 'login/authenticate.html', {'MESSAGE': msg})

def index(request):
    return render(request, 'login/login_form.html')

Ich habe ein Formular, das dies als Aktion hat:

{% url 'login:auth' %}

Und da ist das Problem, wenn ich versuche, die Seite zu laden, erhalte ich:

Reverse for 'auth' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$auth/']

Aber wenn ich das URL-Muster auf setze

url(r'', views.auth, name='auth')

es funktioniert gut, nur setzt es die Aktion als '/'.

Ich habe mich nach einer Antwort umgesehen und verstehe nicht, warum es nicht funktioniert.

Ich habe versucht, das Anmelde-URL-Muster in url (r '^ login / $9$#39;, include ('login.urls', namespace = 'login') zu ändern, und es hat sich nichts geändert.

, views.index, name='index'), url(r'^auth/', views.auth, name='auth'), )

Dies ist Login / Ansichten, py

from django.shortcuts import render
from django.contrib.auth import authenticate

def auth(request):
    user = authenticate(username=request.POST['username'], password=request.POST['password'])
    if user is not None:
        # the password verified for the user
        if user.is_active:
            msg = "User is valid, active and authenticated"
        else:
            msg = "The password is valid, but the account has been disabled!"
    else:
        # the authentication system was unable to verify the username and password
        msg = "The username and password were incorrect."
    return render(request, 'login/authenticate.html', {'MESSAGE': msg})

def index(request):
    return render(request, 'login/login_form.html')

Ich habe ein Formular, das dies als Aktion hat:

{% url 'login:auth' %}

Und da ist das Problem, wenn ich versuche, die Seite zu laden, erhalte ich:

Reverse for 'auth' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$auth/']

Aber wenn ich das URL-Muster auf setze

url(r'', views.auth, name='auth')

es funktioniert gut, nur setzt es die Aktion als '/'.

Ich habe mich nach einer Antwort umgesehen und verstehe nicht, warum es nicht funktioniert.

Ich habe versucht, das Anmelde-URL-Muster in url (r '^ login / $9$#39;, include ('login.urls', namespace = 'login') zu ändern, und es hat sich nichts geändert.

, include('login.urls', namespace='login')), url(r'^admin/', include(admin.site.urls)), )

Und das ist login / urls.py:

from django.conf.urls import patterns, url
from login import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^auth/', views.auth, name='auth'),
)

Dies ist Login / Ansichten, py

from django.shortcuts import render
from django.contrib.auth import authenticate

def auth(request):
    user = authenticate(username=request.POST['username'], password=request.POST['password'])
    if user is not None:
        # the password verified for the user
        if user.is_active:
            msg = "User is valid, active and authenticated"
        else:
            msg = "The password is valid, but the account has been disabled!"
    else:
        # the authentication system was unable to verify the username and password
        msg = "The username and password were incorrect."
    return render(request, 'login/authenticate.html', {'MESSAGE': msg})

def index(request):
    return render(request, 'login/login_form.html')

Ich habe ein Formular, das dies als Aktion hat:

{% url 'login:auth' %}

Und da ist das Problem, wenn ich versuche, die Seite zu laden, erhalte ich:

Reverse for 'auth' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$auth/']

Aber wenn ich das URL-Muster auf setze

url(r'', views.auth, name='auth')

es funktioniert gut, nur setzt es die Aktion als '/'.

Ich habe mich nach einer Antwort umgesehen und verstehe nicht, warum es nicht funktioniert.

Ich habe versucht, das Anmelde-URL-Muster in url (r '^ login / $9$#39;, include ('login.urls', namespace = 'login') zu ändern, und es hat sich nichts geändert.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage