Django-url-params is a reusable Django module allowing users to keep URL parameters during redirection. It can be used for UTM parameters https://en.wikipedia.org/wiki/UTM_parameters or any other URL parameter. Especially when you need to use django redirect.
- Django: 1.10+
Install using pip:
pip install django-url-params
Then add 'urlparams'
to your INSTALLED_APPS
.
INSTALLED_APPS = [
...
'urlparams',
]
Usage is very simple:
from urlparams.redirect import param_redirect
def my_view(request):
# do something ...
return param_redirect(request, 'view_name')
If your reverse url require arguments, just add it on the usual way:
def my_view(request):
# do something ...
return param_redirect(request, 'view_name', arg1, arg2)
With django-url-params it's also possible to add your parameter to the URL easily.
def my_view(request):
request.cparam = {'my_parameter': 'my_value'}
return param_redirect(request, 'view_name')
Parameter will be in your next url: .../my-url/?my_parameter=my_value
.
Note: function will keep existing parameters and append yours.
Django-url-params provides a custom URL_PARAMS_CONF
settings value for use with
different URL conf.
To use this add URL_PARAMS_CONF
in your settings file.
URL_PARAMS_CONF = 'my_custom.url_conf'