首页 > 解决方案 > Django URL 模式已停止匹配

问题描述

我一直在使用专门的会员应用程序(My_Members)对 python 和 django 进行研究。稍微编辑的足迹是:

|-- Billing
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models
|   |   |-- __init__.py
|   |   |-- account.py
|   |   |-- fees.py
|   |   `-- payment.py
|   |-- tests.py
|   |-- urls.py
|   |-- views
|   |   |-- __init__.py
|   |   |-- account.py
|   |   `-- fees.py
|   `-- views.py
|-- My_Members
|   |-- __init__.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- Manager
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models
|   |   |-- __init__.py
|   |   `-- group.py
|   |-- tests.py
|   `-- views
|       |-- __init__.py
|       `-- group.py
|-- Members
|   |-- __init__.py
|   |-- account_adapter.py
|   |-- admin.py
|   |-- apps.py
|   |-- forms
|   |   |-- __init__.py
|   |   |-- profile.py
|   |   `-- student.py
|   |-- models
|   |   |-- __init__.py
|   |   |-- profile.py
|   |   |-- rank.py
|   |   |-- student.py
|   |   `-- title.py
|   |-- urls.py
|   `-- views
|       |-- __init__.py
|       |-- group.py
|       |-- index.py
|       |-- profile.py
|       `-- student.py

下面urls.py看起来My_Members像:

from django.conf.urls import include
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import path, re_path

from Members.views import index

urlpatterns = [
    path('accounts/', include('allauth.urls')),
    path('Members/', include('Members.urls')),
    path('Billing/', include('Billing.urls')),
    path('admin/', admin.site.urls),
    re_path(r'^$', index, name='index'),
]

urlpatterns += staticfiles_urlpatterns()

成员/urls.py 看起来像:

from django.urls import path, re_path

from .views import index
from .views import profile
from .views import student

urlpatterns = [
    path('Members/Profile/<uuid:profile_id>/edit', profile.Update.as_view(),
         name="profile-update"),
    path('Members/Profile/<uuid:profile_id>/delete', profile.Delete.as_view(),
         name="profile-delete"),
    path('Members/Profile/create', profile.Create.as_view(),
         name="profile-create"),
    path('Members/Student/<uuid:student_id>/edit', student.Update.as_view(),
         name="student-update"),
    path('Members/Student/<uuid:student_id>/delete', student.Delete.as_view(),
         name="student-delete"),
    path('Members/Student/<uuid:account_id>/create', student.Create.as_view(),
         name="student-create"),
    path('Members/', index, name='index'),
]

Billing/urls.py 是:

from django.urls import path, re_path

from Members.views import index
from .views import account

urlpatterns = [
    path('Billing/Account/<uuid:profile_id>/create', account.Create.as_view(),
         name="account-create"),
    path('Billing/', index, name='index'),
]

结算网址文件是新的。自从添加它之后,几乎所有其他 URL 模式似乎都失败了。例如:网址:

Members/Profile/ba73e105-325a-42d2-9476-20402d130189/edit

产生错误:

Page not found (404)
Request Method: GET
Request URL:    http://localhost:8000/Members/Profile/ba73e105-325a-42d2-9476-20402d130189/edit
Using the URLconf defined in CIAMembers.urls, Django tried these URL patterns, in this order:

accounts/
Members/ Members/Profile/<uuid:profile_id>/edit [name='profile-update']
Members/ Members/Profile/<uuid:profile_id>/delete [name='profile-delete']
Members/ Members/Profile/create [name='profile-create']
Members/ Members/Student/<uuid:student_id>/edit [name='student-update']
Members/ Members/Student/<uuid:student_id>/delete [name='student-delete']
Members/ Members/Student/<uuid:account_id>/create [name='student-create']
Members/ ^$ [name='index']
Members/ Members/ [name='index']
Billing/
admin/
^$
^static\/(?P<path>.*)$
The current path, Members/Profile/ba73e105-325a-42d2-9476-20402d130189/edit, didn't match any of these.

我的目标路径就在错误报告列表的顶部。我错过了什么?

编辑

@jchung 是正确的。在编辑一堆文件后,我也忘记终止并重新启动 PyCharm 调试会话。只是重新启动,而不是终止和启动挂起到已编辑文件的旧缓存版本。

标签: django

解决方案


推荐阅读