问题
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?
回答1:
(?P<obj_ctype_name>foo|bar|baz)
来源:https://stackoverflow.com/questions/1996305/url-regex-in-django-with-limited-set-of-words