#StackBounty: #django #django-views #django-urls Is there a way to get a referring URL via a custom HTTP header?

Bounty: 100

I am currently using the following function to get a referring view:

def get_referer_view(request, default=None):   
    referer = request.META.get('HTTP_REFERER')
    if not referer:
        return default

    # remove the protocol and split the url at the slashes
    referer = re.sub('^https?://', '', referer).split('/')
    if referer[0] != request.META.get('SERVER_NAME'):
        return default

    # add the slash at the relative path's view and finished
    referer = u'/' + u'/'.join(referer[1:])
    return referer

If I redirected the view as a result of programmatic logic, e.g…

return HttpResponseRedirect('dashboard')

…is there a way to get the referring view without using HTTP_REFERER so that I can use that variable in the redirected view? This is not always set in the headers of the browser.

Note because the views are redirected pro grammatically, I can’t use POST to collect the data.

Perhaps its possible to set and retrieve a custom header somehow?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.