How do I get the raw request path (everything after the host name and the port) in Django?
I tried request.get_full_path(), but it doesn’t work for some URLs.
For example, when the URL is http://localhost:8000/data/?, the result is /data/ instead of /data/?.
I know that the server receives the full string because it show "GET /data/? HTTP/1.1" 200 642 in the terminal.
You can use request.build_absolute_uri()
Depends on source code:
Builds an absolute URI from the location and the variables available in this request. If no
locationis specified, the absolute URI is built onrequest.get_full_path(). Anyway, if the location is absolute, it is simply converted to an RFC 3987 compliant URI and returned and if location is relative or is scheme-relative (i.e.,//example.com/), it is urljoined to a base URL constructed from the request variables.
Getting access to the raw URL depends on your setup. I'm not aware of a way to do this with Django's development server.
HTTPRequest.META is described as follows:
A dictionary containing all available HTTP headers. Available headers depend on the client and server, but here are some examples:
If you're running gunicorn, request.META["RAW_URI"] might give you what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With