I have a problem with <a> Tag when using block content in django

Viewed 37

First of all I am new to django. I have a project with 4 pages and pages root is look like below:

myProject/create/
myProject/create/project
myProject/create/activity
myProject/create/discipline

I made a base.html file in templates/myapp/base.html and add a sidebar there. I added links of all pages in in base.html to access to other pages. then with the {% extend %} formula I extended sidebar from this page to see a it on other pages too and its working. So my structure of project is look like this:

myProject
├── create
│   ├── project
│   ├── activity
│   ├── discipline

when I am in "create" page and I click on project page, I goes on that page and its working. but the problem is when I am in sub pages like "project" page and I click on other pages (ex: activity) it goes to: MyProject/Create/project/activity which is not true. what should I do to be able to go to myProject/create/activity and not to MyProject/Create/project/activity from sub pages ?

1 Answers

You should work with a leading slash (/), otherwise you are defining a query-relative url [w3.org]. By using a leading slash, it means it will keep the hostname, and replaces the old path with the new path.

You thus link with:

<a href="/myProject/create/project">…</a>

That being said, it is often better to resolve the URLs with the {% url … %} template tag [Django-doc].

Related