andyk
andyk

Reputation: 171

Django: Multiple parameters in URLs reverse resolution without querystrings or captured parameters

Without using query strings (like ?case=/2/), nor captured parameters in the url conf (like ?P) (so they dont show up in the url), is there a way to pass parameters to a view function when using URLs reverse resolution?

Hopefully an example will clarify my question:

With captured parameters I could do:

views.py ... return HttpResponseRedirect(reverse('videos:show_details', args=[video.id]))

urls.py ... url(r'^club/(?P\d+)/$',views.details, name='show_details'), ...

But what if the view details needs / accepts more parameters, for example:

def details (request, video_id, director='', show_all=True):

And we dont want them to show up in the url?

Any way of using args or kwargs without them being in the url?

Im sure Im missing something trivial here :S

Hopefully someone can point me in the right direction. Thanks!

Upvotes: 1

Views: 937

Answers (1)

knbk
knbk

Reputation: 53729

I'm not sure this is what you mean, but you can pass extra arguments to the url pattern. This allows multiple urls that point to the same view to use different arguments:

url(r'^club/(?P<pk>\d+)/$', views.details, kwargs={'show_all': False}, name='show_details')

Upvotes: 0

Related Questions