[英]The current path, account/login/, didn't match any of these?
I'm trying to access my project (local), and I am getting this traceback:我正在尝试访问我的项目(本地),并且收到此回溯:
traceback追溯
Page not found (404)
Request Method:
GET
Request URL:
http://127.0.0.1:8000/account/login/
Using the URLconf defined in tutorial.urls, Django tried these URL patterns, in this order:
[name='login_redirect']
admin/
account/ ^$
account/ ^login$
account/ ^logout$
account/ ^register$ [name='register']
account/ ^profile$ [name='view_profile']
account/ ^profile/edit$ [name='edit_profile']
account/ ^change-password$ [name='change_password']
account/ ^reset-password$ [name='reset_password']
account/ ^reset-password/done$ [name='password_reset_done']
account/ ^reset-password/confirm(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A- Za-z]{1,13}-[0-9A-Za-z]{1,23})/$ [name='password_reset_confirm']
account/ ^reset-password/complete$ [name='password_reset_complete']
The current path, account/login/, didn't match any of these.
Main/urls.py主/urls.py
from django.contrib import admin
from django.urls import path, re_path, include
from tutorial import views
urlpatterns = [
path('', views.login_redirect, name='login_redirect'),
path('admin/', admin.site.urls),
path('account/', include('accounts.urls')),
]
project/urls.py项目/urls.py
from django.conf.urls import url
from . import views
from django.contrib.auth import views as auth_views
from django.contrib.auth.views import (
PasswordResetView,
PasswordResetDoneView,
PasswordResetConfirmView,
PasswordResetCompleteView,
)
from django.urls import re_path
urlpatterns = [
url(r'^$', views.home),
url(r'^login$', auth_views.LoginView.as_view(template_name='accounts/login.html')),
url(r'^logout$', auth_views.LogoutView.as_view(template_name='accounts/logout.html')),
url(r'^register$', views.register, name='register'),
url(r'^profile$', views.view_profile, name='view_profile'),
url(r'^profile/edit$', views.edit_profile, name='edit_profile'),
url(r'^change-password$', views.change_password, name='change_password'),
url(r'^reset-password$', PasswordResetView.as_view(), name='reset_password'),
url(r'^reset-password/done$', PasswordResetDoneView.as_view(), name='password_reset_done'),
url(r'^reset-password/confirm(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,23})/$',
PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
url(r'^reset-password/complete$', PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
middleware.py中间件.py
import re
from django.conf import settings
from django.shortcuts import redirect
class LoginRequiredMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
return response
def process_view(self, request, view_func, view_args, view_kwargs):
assert hasattr(request, 'user')
if not request.user.is_authenticated:
if True:
return redirect(settings.LOGIN_URL)
settings.py设置.py
LOGIN_REDIRECT_URL = '/account/login'
LOGIN_URL = '/account/login/'
What is the problem here?.这里有什么问题?。 The redirect works, I have a feeling its in urlpatterns but cannot for the life figure it out.
重定向有效,我有一种感觉,它在 urlpatterns 中,但终生无法弄清楚。 Driving me crazy today.
今天把我逼疯了。 Thanks for the help and sorry for the essay!
感谢您的帮助,并对文章感到抱歉!
Your LOGIN_URL
setting has a trailing slash:您的
LOGIN_URL
设置有一个尾部斜杠:
LOGIN_URL = '/account/login/'
But your URL pattern for login
does not allow a trailing slash.但是您的
login
URL 模式不允许尾部斜杠。
url(r'^login$', auth_views.LoginView.as_view(template_name='accounts/login.html')),
You could remove the slash from the LOGIN_URL
.您可以从
LOGIN_URL
删除斜杠。 However, the usual practice in Django is to include a trailing slash in URLs.但是,Django 中的通常做法是在 URL 中包含尾部斜杠。 Then, the default behaviour will redirect any requests from
/accounts/login
to /accounts/login/
with a trailing slash.然后,默认行为会将来自
/accounts/login
任何请求重定向到/accounts/login/
并带有斜杠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.