About Modifying Query String Parameters
Use a mutable QueryDict
to create a URL with modified query parameters. For example, to modify the page parameter of the current page URL, you can do this:
from django.http import QueryDict
next_page_url = None
if object_list.has_next():
q = QueryDict(request.META["QUERY_STRING"], mutable=True)
q["page"] = object_list.next_page_number()
params = q.urlencode()
next_page_url = "{protocol}://{host}{path}?{params}".format(
protocol=request.scheme,
host=request.get_host(),
path=request.path,
params=params,
)
Tips and Tricks Programming Django 2.2 Django 1.11 Django 1.8
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent app
For Django websites that use cookies.
Django App for You