Home > Software engineering >  Get anchor and all params in request path
Get anchor and all params in request path

Time:05-16

For a development with django, I try to get the parameters of my url. my path : http://127.0.0.1:8000/categories/candy#bubblizz candy is my view avec #bubblizz is my id anchor.

A lot of documentation on request items but impossible to find how to get the anchor

{{ request.build_absolute_uri }}   => http://127.0.0.1:8000/categories/candy
{{ request.get_full_path }}        => /categories/candy
{{ request.path }}                 => /categories/candy
{{ request.META.PATH_INFO}}        => /categories/candy

The goal is to test the presence of the anchor in the url.

{% if bubblizz in request.anchor %}Yeah{% endif %}

Does anyone have an idea? Or documentation that might help?

Thanks

CodePudding user response:

The part after the hash is called the fragment [wiki], these are not send to the server, as is specified in the Wikipedia article:

Clients are not supposed to send URI fragments to servers when they retrieve a document, and without help from a local application (see below) fragments do not participate in HTTP redirections.

Django thus never is given the #bubblizz part of the URI. You will need to work with some JavaScript to detect the fragment, and for example make an AJAX query and update the DOM accordingly. You can do this with window.location.hash [mdn] to get the fragment for the URI of the window.

  • Related