找不到Django网址模式

Mar*_*des 0 python django

我遵循了一个教程,允许用户注册帐户,但似乎找不到url路径。当我为其设置名称时,它允许我访问127.0.0.1:8000/帐户/注册,但不能访问127.0.0.1:8000/注册。

我尝试将urlpatterns从路径更改为url方法,但这不能解决问题。

我的文件结构如下:

App:
   accounts:
           urls.py
           views.py
           ...
   Server:
         settings.py
         urls.py
         ...
   templates:
            registration:
                        login.html
            base.html
            home.html
            signup.html
   manage.py

Run Code Online (Sandbox Code Playgroud)

在我的Server \ urls.py中,

from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('accounts.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('', TemplateView.as_view(template_name='home.html'), name='home'),
]
Run Code Online (Sandbox Code Playgroud)

在我的account \ urls.py中,

from django.urls import path

from . import views


urlpatterns = [
    path('signup/', views.SignUp.as_view(), name='signup'),
]
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

Using the URLconf defined in Server.urls, Django tried these URL patterns, in this order:
   admin/
   accounts/
   accounts/
   [name='home']
The current path, signup, didn't match any of these.
Run Code Online (Sandbox Code Playgroud)

我不太确定发生了什么,因为我还是Django的新手,并在学习过程中忙于学习。

Iva*_*tin 5

path('accounts/', include('accounts.urls')),
Run Code Online (Sandbox Code Playgroud)

表示所有来自accounts.urls的网址都应以开头accounts/。如果那不是您想要的-将此编辑为

path('/', include('accounts.urls')),
Run Code Online (Sandbox Code Playgroud)

并且accounts.urls将被视为最高级别的网址。