我已經在我的項目模板下面的鏈接:Django的NoReverseMatch,不是註冊名稱空間
<li><a id="toggleLogin" href= "{% url 'login' %}" onclick="toggleLogin();" ><span>Login</span></a></li> <!-- login app
-->
項目網址是:
url(r'^login/',loginViews.user_login,name='login'),
應用網址是:
url(r'^$',views.user_login,name='user_login'),
and the ap摺疊觀點是:
def user_login(request):
"""User at login view """
#
if request.method == 'POST':
# First get the username and password supplied
username = request.POST.get('username')
password = request.POST.get('password')
# Django's built-in authentication function:
user = authenticate(username=username, password=password)
# If we have a user
if user:
#Check it the account is active
if user.is_active:
# Log the user in.
login(request,user)
# Send the user back to some page.
# In this case their homepage.
return HttpResponseRedirect(reverse('index'))
else:
# If account is not active:
return HttpResponse("Your account is not active.")
else:
print("Someone tried to login and failed.")
print("They used username: {} and password: {}".format(username,password))
return HttpResponse("Invalid login details supplied.")
else:
#Nothing has been provided for username or password.
return render(request, 'login.html', {})
但一旦鏈接的點擊,則返回Django的以下錯誤:
NoReverseMatch at /login/
'login_app' is not a registered namespace
應此命名空間中的項目的URL文件進行註冊呢?