Django - urls.py REGEX

倖福魔咒の 提交于 2020-01-07 05:41:05

问题


I am having some trouble writing the regex portion of the url for a Django project.

I want to be able to route along with capturing a profile ID

URL Example: www.somesite.com/profile/12345678901

This is what I have so far

url(r'^profile/$', views.dashboard, name='widget')

Whats the correct REGEX that should go after the profile/? How would I capture the numeric part after the profile/? once I am in the view?

Thanks,


回答1:


url(r'^profile/(?P<id>[\d]+)/$', profile_view, name="profile"),

and in the view

def profile_view(request, id):
    #some logic here...


来源:https://stackoverflow.com/questions/17635255/django-urls-py-regex

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