Shardul
Shardul

Reputation: 100

How to prevent django from appending the url everytime?

I created two html file (home.html, admin.html). Both are linked to each other. Django, first opens up the home.html, with the url http://127.0.0.1:8000/home and as soon as a particular link is clicked, it is supposed to open the admin.html. Similarly, when a particular linked in admin.html is clicked, it opens up home.html.

But, the url keeps on extending eg.

127.0.0.1:8000/home -> 127.0.0.1:8000/home/admin -> 127.0.0.1:8000/home/admin/home

and so on.....

How to stop django from constantly appending the url.

Upvotes: 1

Views: 2697

Answers (1)

Maxime Lorant
Maxime Lorant

Reputation: 36161

It looks like you have something like <a href="admin/"> in your template. This tells to the browser "go to the subdirectory admin please", while what you want is "go to the URL /admin from the root of my website".

What you need is to use the {% url %} templatetag, which will prevent those sort of mistakes:

<a href="{% url 'my_admin_view' %}">Admin link</a>

Upvotes: 2

Related Questions