Django Url Endswith Regex In Url Path
I need to support following urls in single url regex. /hotel_lists/view/ /photo_lists/view/ /review_lists/view/ how to support all above urls in single views? I tried something l
Solution 1:
If you wish to capture the resource type in the view, you could do this:
url(r'^(?P<resource>hotel|photo|review)_lists/view/$', 'admin.views.customlist_handler'),
Or to make it more generic,
url(r'^(?P<resource>[a-z]+)_lists/view/$', 'admin.views.customlist_handler'), #Or whatever regex pattern is more appropriate
and in the view
defcustomlist_handler(request, resource):
#You have access to the resource type specified in the URL.
...
You can read more on named URL pattern groups here
Post a Comment for "Django Url Endswith Regex In Url Path"