[Fixed]-Using page slug to open a specific tab in django template


In the URL


#my_courses is a fragment, not a slug. URL fragments only exist in the browser, they are not sent to the web server, and so you URL routing and templates will never see them.

When the user visits that url, what is sent to the server is


And that’s the page that is returned. You’d need JavaScript on the page to inspect the full URL (through document.location.href) and update the page accordingly.

A slug, on the other hand, is not separated by a # character, and forms part of the URL that is sent to the server. That can be seen by Django, and inform the view as to what to render in the template. You would need to redesign your URLs to take advantage of that, though.

Leave a comment