Django 的 slug url 正则匹配

匿名 (未验证) 提交于 2019-12-03 00:04:02

.*/edit//delete/

urlpatterns = [     #...     url(r'^(?P<slug>.*)/$', post_detail, name='detail'),     url(r'^(?P<slug>.*)/edit/$', post_update, name='update'),     url(r'^(?P<slug>.*)/delete/$', post_delete), ]

[-\w+]-

urlpatterns = [     #...     url(r'^(?P<slug>[-\w]+)/$', post_detail, name='detail'),     url(r'^(?P<slug>[-\w]+)/edit/$', post_update, name='update'),     url(r'^(?P<slug>[-\w]+)/delete/$', post_delete), ]

参考:

https://www.jianshu.com/p/8207b66db9ca

https://www.cnblogs.com/yang-wei/p/9997776.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!