0

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 Answer 1

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

and in the view

def profile_view(request, id):
    #some logic here...
Sign up to request clarification or add additional context in comments.

1 Comment

+1. While this would work, i would recommend the Named groups - Something like url(r'^profile/(?P<id>[\d]+)/$', profile_view, name="profile"), to keep things more explicit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.