首页 > 解决方案 > Django url参数错误

问题描述

这是我的问题:

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/

这是我的网址文件:

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

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

如果你有任何想法?

谢谢并恭祝安康

标签: pythondjango

解决方案


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

path("bio/<slug:username>/", views.bio, name='bio')

推荐阅读