Shoaib Raza
Shoaib Raza

Reputation: 31

How we can return extra parameter with the 'HTTP_REFERER' URL in Django views?

url = request.META.get('HTTP_REFERER') 

return HttpResponseRedirect(url) 

This URL is used to redirect to the current page and I want to send a parameter with it. How I can do that?

Upvotes: 3

Views: 322

Answers (1)

user3772914
user3772914

Reputation: 41

import urllib.parse

params = {"test": 1, "q": "some search string"}
query_string = urllib.parse.urlencode(params)
url = request.META.get('HTTP_REFERER')
if not url:
    url = request.META.get('some-other-header')
url += "?" + query_string

Upvotes: 0

Related Questions