问题
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