因此,除了此注销URL之外,我新启动的Django项目中的所有命令都工作正常。我正在使用django = 1.11.17和python3。当我尝试从帐户注销时,这是我得到的错误。
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/%25%20url%20'accounts:logout'%20%25
Using the URLconf defined in conspiverse_project.urls, Django tried these URL patterns, in this order:
^$ [name='home']
^test/$ [name='test']
^thanks/$ [name='thanks']
^admin/
^accounts/
^accounts/
The current path, % url 'accounts:logout' %, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
帐户/urls.py
from django.conf.urls import url, include
from django.contrib.auth import views as auth_views
from . import views
app_name = 'accounts'
urlpatterns = [
url(r"login/$", auth_views.LoginView.as_view(template_name="accounts/login.html"),name='login'),
url(r"logout/$", auth_views.LogoutView.as_view(template_name="thanks.html"), name="logout"),
url(r"signup/$", views.SignUp.as_view(), name="signup"),
]
project / urls.py
from django.conf.urls import url, include
from django.contrib import admin
from . import views
urlpatterns = [
url(r"^$", views.HomePage.as_view(), name="home"),
url(r"^test/$", views.TestPage.as_view(), name="test"),
url(r"^thanks/$", views.ThanksPage.as_view(), name="thanks"),
url(r"^admin/", admin.site.urls),
url(r"^accounts/", include("accounts.urls", namespace="accounts")),
url(r"^accounts/", include("django.contrib.auth.urls")),
]
settings.py
STATIC_URL = '/static/'
STATICFILES_DIR = [os.path.join(BASE_DIR,'static')]
LOGIN_REDIRECT_URL = 'test'
LOGOUT_REDIRECT_URL = 'thanks'
我尝试验证URL路径,对几乎所有内容进行交叉检查,这使我发疯。非常感谢您的帮助!