29

As in the title: How can I access the URL hash/fragment (the part following the hash #, or 'pound symbol' in US English) from a Django view and so, I suppose, from a Django Request object?

I've not found enough information on the documentation here available: http://docs.djangoproject.com/en/dev/ref/request-response/

P.S. Assume the fragment is included in the URL sent to the server. (I have verified this in my case, where I'm not actually using a browser.)

Michael Scheper
  • 6,514
  • 7
  • 63
  • 76
Andrea Zilio
  • 4,444
  • 3
  • 29
  • 34
  • While this problem is unsolvable by server-side, it is solvable by client-side https://stackoverflow.com/questions/73470437/retrieving-id-atribute-from-url/73470609#comment129745272_73470609 – oruchkin Aug 24 '22 at 09:51

1 Answers1

42

This is not sent to the server, by definition. From URI References: Fragment Identifiers on URIs :

"The HTTP engine cannot make any assumptions about it. The server is not even given it."

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • This is true, but in my specific case the fragment part is sent to the server (I see it from the apache log). It's a strange situation, but I know that HTTP requests to that URL will include the fragment part. (It's not a browser to send the request). So how (if possible) can I access it? – Andrea Zilio Feb 02 '10 at 01:15
  • 3
    I realize some user agents (e.g. the version of curl I have installed) send it. But I think this is clearly a bug. In fact, this was just fixed in curl CVS (http://curl.haxx.se/cvs.cgi/curl/lib/url.c?r1=1.826&r2=1.827). – Matthew Flaschen Feb 02 '10 at 02:03
  • 2
    With high probability the node sending the request to that url is in fact using CURL and so your comment is really helpful! Knowing that CURL has been fixed to not send the fragment anymore is very important and will make me reconsider my approach. Thanks ;) – Andrea Zilio Feb 02 '10 at 02:20
  • 1
    The above CVS link rotted, so use this [git one](https://github.com/bagder/curl/commit/9bd03483ce6983852d41f5f69cb74827c9defc26). – Matthew Flaschen Mar 18 '11 at 04:44