Django automatically append hyperlink url to the existing url


I am a beginner of django, currently I am having a url problem.

For example, in our base.html page, we hard coded some hyper link tag like <a href="home.html">home</a> and if we try to navigate to this page from other page for like localhost:8000/shop_online.html/category/jewelry and click the hyperlink then we will be redirected to the home page but with the url looks like this: localhost:8000/shop_online.html/category/jewelry/index.html.

I think this has something to do with the and the hard coded hyper link tag, but I am confused and don’t know how to solve this, I think is a pretty easy problem.


You should add / in your href attribute:

<a href="/home.html">home</a>

However, probbably the better solution is to use url tag. So it should look like:

<a href="{% url index %}">home</a>

Here you have a documentation about url dispatcher in Django.

And one more thing: you don’t need to have this *.html extension in your urls.

Answered By – Konrad Hałas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published