Essentially I have a single view that accepts different operations and a varying number of parameters. This was previously working in the following state:
url(r'^items/(?P<op>[a-zA-Z0-9]+)/(?P<id>[0-9]+)$', login_required(ItemOpView.as_view()), name='my.views.item_op'),
Which always provides kwargs['op'] and kwargs['id'] to the view. This allows for URLs such as:
- items/delete/1
- items/show/1
- items/hide/1
However I’d like to adapt the rule to also accept the following:
- items/relocate/1/2 meaning I’d like to have
kwargs['id2']as well.
I’ve attempted to do this with the rule:
url(r'^items/(?P<op>[a-zA-Z0-9]+)/(?P<id>[0-9]+)(?/)(?P<id2>[0-9]+)$', login_required(ItemOpView.as_view()), name='my.views.item_op'),
However this doesn’t work and just gives a 404.
Thanks for any advice!
Just add another url entry like so:
And make sure your view accepts a default parameter (like
None) for the second parameter.