1

I am new to Django. I am trying to add Navigation bar to each page, so when I go to one of page (say about) and then from there when I go to another (say contact) path error occurs.

Home page

Then i route to about page

Then from about to contact

Here in navigation.html

<nav>
    <ul>
        <li>
            <a href="{% url 'reports:index' %}">Reports</a>
        </li>
        <li>
            <a href="about">About us</a>
        </li>
        <li>
            <a href="contact">Contact us</a>
        </li>
    </ul>
</nav>  

So I want, how should I clear my route and go to any nav pages from any current page.

2 Answers2

2

Try to add '/' to your links, in navigation.html:
<a href="/about">About us</a> and <a href="/contact">Contact us</a>

as you can see, when you go from page About to page Contact, your url in browser looks like 127.0.0.1:8000/about/contact, but in trydjango.urls you defined path like: 127.0.0.1:8000/contact

Edvard Krol
  • 95
  • 1
  • 11
1

You have trydjango.urls file which contains URLs such as about/, contact/, products/ etc so when you click on an URL on the home page it takes you to the URL about page but after that when you click on any other URL it appends to the existing URL i.e about/products. So what you want to do is you need to make URLs as relative which you can do by adding /about or /product in your href tag like.

<a href="/contact">Contact us</a>

This will look for /contact in your trydjango file and will point to the URL. Read the URL dispatcher docs and try to use the url tage where ever possible bettter answer here

Anidh Singh
  • 302
  • 2
  • 7
  • 19