私はdjango 1.6(とpython 2.7)で簡単なログインアプリを作っています。Django NoReverseMatch
これは、サイトのurl.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
import login
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('login.urls', namespace='login')),
url(r'^admin/', include(admin.site.urls)),
)
であり、これはログイン/ 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'),
)
これは、ログイン/ビューで、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')
これをアクションとして持つフォーム:
唯一Reverse for 'auth' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$auth/']
しかし、私は
url(r'', views.auth, name='auth')
にURLパターンを設定した場合、それは正常に動作し、それは:
そして問題は、私はページをロードしようとすると、私が得る、ここでそれはですアクションを '/'に設定します。
私は答えを探していましたが、なぜ動作しないのか分かりません。
ログインURLパターンをurl(r '^ login/$'、include( 'login.urls'、namespace = 'login'))に変更しようとしましたが、何も変更されませんでした。
[NoReverseMatchエラーとは何ですか?また修正するにはどうすればいいですか?](http://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do- i-fix-it) – Sayse