Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL regex in django with limited set of words

Tags:

regex

url

django

Given the following django URL conf. entry:

url(r'^(?P<obj_ctype_name>\w+)/(?P<obj_id>\d+)/$',
    views.obj_view,
    name='obj_view')

How would I rewrite the parameter (?P<obj_ctype_name>\w+) to enforce that it may only be one of "foo" "bar" or "baz" and still keep it as a named parameter?

like image 414
Pet Halibut Avatar asked Jan 03 '10 21:01

Pet Halibut


1 Answers

(?P<obj_ctype_name>foo|bar|baz)

like image 185
Ben James Avatar answered Nov 02 '22 11:11

Ben James