user1672155
user1672155

Reputation:

Django links on base template

I'm currently working on my static side of the site. And creating the HTML/CSS/JS stuff. In the base html i have some links. One of them is "about" that will lead to the ...:8000/about Now when im on the about page there are the same links cause they are in the base template. When i click on them now i get ...:8000/about/about and it will go on adding the /about each time i click.

How should i get this link to always point to ...:8000/about

Thank you.

Upvotes: 0

Views: 1114

Answers (1)

Absolute URLs.. start your links with /

<a href="/about/"> instead of <a href="about/">

Also, if it will "add /about" each time you click, that means you're re-rendering your view... which means your URLConf probably has a too-broad regex (make sure your line is terminated by a /$

Kind of sounds like you have a line like url(r'^about/', 'foo') where /about/about/about will continue to match.


It's also best practice to use the {% url %} tag via named urls. Sooner or later you'll change a URL and thank everyone for it.

https://docs.djangoproject.com/en/dev/topics/http/urls/#named-groups

Upvotes: 4

Related Questions