url rewriting - Is it possible to make positional argument optional in URL in Django -


i have in url file

(r'^new/(?p<object_class>\w+)/(?p<action>\w+)/(?p<object_id>\d+)/$', create_object)

now url /new/book/edit/5 working fine

but if /new/book/create says nor url matched.

is possible third argumrent optional can use 1 url rule above cases

(r'^new/(?p<object_class>\w+)/(?p<action>\w+)/((?p<object_id>\d+)/)?$', create_object) 

this should it. (notice wrapped object_id , / in (..)? make optional)

now object_id should none in view.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -