Since Django 5.1, this is automatically handled by the querystring template tag. Documentation: https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#querystring
querystring