Django - urls.py REGEX

2019-09-01 18:45发布

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条回答
够拽才男人
2楼-- · 2019-09-01 19:26
url(r'^profile/(?P<id>[\d]+)/$', profile_view, name="profile"),

and in the view

def profile_view(request, id):
    #some logic here...
查看更多
登录 后发表回答