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> })
- is use of
reverse
reasonable/acceptable, and - 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
Post a Comment