3

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?

manniL
  • 6,312
  • 4
  • 40
  • 64
Hassan Baig
  • 13,553
  • 22
  • 85
  • 180

1 Answers1

1

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.

C14L
  • 11,487
  • 4
  • 34
  • 50