使用Django 2.1时出现以下错误:
Page not found (404)
Request Method: POST
Request URL: http://localhost:8000/user-accounts/%5Eregister/
Using the URLconf defined in my_project.urls, Django tried these URL patterns, in this order:
admin/
user-accounts/ ^register/$ [name='register']
user-accounts/ ^login/$ [name='login']
user-accounts/ ^logout/$ [name='logout']
bank-accounts/
The current path, user-accounts/^register/, didn't match any of these.
当我单击base.html中设置的标题中的链接时,在浏览器中得到了奇怪的URL http://localhost:8000/user-accounts/%5Eregister/
。 base.html中的链接是:
<li class="dropdown-header"><a href="{% url 'user-accounts:register' %}">Register</a></li>
<li class="dropdown-header"><a href="{% url 'user-accounts:login' %}">Login</a></li>
用户帐户应用urls.py:
from django.urls import path
from django.contrib import admin
from . import views
app_name = 'user-accounts'
urlpatterns = [
path(r'^register/$', views.register, name='register'),
path(r'^login/$', views.user_login, name='login'),
path(r'^logout/$', views.user_logout, name='logout'),
]
项目urls.py:
from django.contrib import admin
from django.urls import path, include
from user_accounts.views import register
urlpatterns = [
path('admin/', admin.site.urls),
path('', register),
path(r'user-accounts/', include('user_accounts.urls')),
path(r'bank-accounts/', include('bank_accounts.urls')),
]