[Answer]-How to set 'next' parameter via extra_context in Django

1πŸ‘

βœ…

The kwargs argument in reverse is used when an URLConf regex contains named groups.

Example:

# For a URL defined this way:
url(r'^users/(?P<user_id>\d+)/$', my_view, name='user_detail')

# You'll use reverse this way:
reverse('user_detail', kwargs={'user_id': some_user_id})

What you want is to add GET parameters to your URL. Which you can achieve this way:

from urllib import urlencode

bare_url = urlresolvers.reverse('login')
encoded_get_params = urlencode({'next': next})
separator = '&' if '?' in bare_url else '?'
url = '{}{}{}'.format(bare_url, separator, encoded_get_params))
πŸ‘€aumo

Leave a comment