Django url参数错误

问题描述 投票:0回答:1

这是我的问题:

Using the URLconf defined in Rase.urls, Django tried these URL patterns, in this order:

admin/
[name='index']
bio/<slug:username>/$ [name='bio']
The current path, bio/bussiere/, didn't match any of these.

网址是:

http://localhost:8000/bio/bussiere/

这是我的url文件:

from django.urls import include, path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path("bio/<slug:username>/$", views.bio, name='bio'),
]

如果你有任何想法?

感谢致敬

python django
1个回答
1
投票

您正在使用Django 2.0.X,其中url发生了很大变化。使用path()时,您不需要使用regex作为url,只需删除尾随的$。所以网址应该是 -

path("bio/<slug:username>/", views.bio, name='bio')
© www.soinside.com 2019 - 2024. All rights reserved.