Hassan Baig Hassan Baig - 7 months ago 37
HTML Question

Altering HTTP_REFERER for use in Django template

In a Django template, the following takes me to the referring page:

<a href="{{ request.META.HTTP_REFERER }}">Referring Page</a>


But if I were using anchor tags, and the referring page was http://example.com/example/#section7,
{{ request.META.HTTP_REFERER }}
wouldn't contain the anchor information.

Is there a way I can alter
{{ request.META.HTTP_REFERER }}
(for instance, in my views.py) such that the anchor tag information is preserved?

Answer

No, because the anchor # value is never transferred to the server side. Its is purely a client site thing to jump to defined parts of a page.

Somewhat unrelated: that is why, years ago, Google came up with the #!, an anchor marker that the Google bot would spider, instead of ignore like the regular # value. The biggest user for that was Twitter, iirc. With Javascript's pushstate() becoming a thing, the #! got forgotten.

Back on topic, the server will never know about any # or #! values, and thus the HTTP_REFERER will not contain it.

Comments