How can I pass named arguments to a Django view method? -


i have view method 2 additional parameters:

def foo(request, email, token):     ... 

and need use reverse generate url:

    ...     url = urlresolvers.reverse(         'my_app.views.foo',         kwargs={ 'token': <token>, 'email': <email> }) 
  1. is use of reverse reasonable/acceptable, and
  2. what url pattern foo like?

1 - yes, far goes, of course fail without urlpattern. can use either args or kwargs, depending on case. here can use args, both required args view function.

2 - here's urlpattern going, regex example, don't know regex needs be.

url(r'^/(?p<email>[-\w]+)/(?p<token>\d{1,2})/$', 'views.foo', name='foo'), 

named urls pattern habit of doing. can pass name reverse function too:

url = urlresolvers.reverse(     'foo',     args=['<email>', '<token>'] 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -