Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Retrieving ID atribute from URL

In my django project i have a url:

https://example.com/nice_page#123

This url will lead user to particular post on my page, this is an example how it works on stackoverflow:

What is the "N+1 selects problem" in ORM (Object-Relational Mapping)? (it is a link to particular answer, and your browser will move you right to this answer.)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My goal is to get this #123 id from url.

I can’t do it with django’s META data by request.META it doesn’t show this #123 id, it only returns me https://example.com/nice_page

How can i get this #123 id?
I would prefer making it with django, but javascript is also acceptable.

Update: as follows from the comments, thanks to –
Willem Van Onsem and Ankit Tiwari, this task is unsolvable by server-side (by django) How to access url hash/fragment from a Django Request object

>Solution :

Yes, only with JavaScript. E.g. using an example from here:

const url = new URL('https://example.com/nice_page#123');
console.log(url.hash); // Logs: '#123'

Or reference the hash of the current URL in a browser:

console.log(window.location.hash);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading