Ibrahim
Ibrahim

Reputation: 51

Django nav link not working

When I change from one page to another nothing happens except teacher page and from teacher page I cannot go any other pages!

            <ul class="sidebar-menu" data-widget="tree">

                <li class="treeview">
                    <a href="Dashboard:index">
                      <i class="fa fa-dashboard"></i>
                      <span>Current Courses</span>
                    </a>
                </li>

                <li class="treeview">
                    <a href="Dashboard:result">
                      <i class="fa fa-th"></i>
                      <span>All Batch Records</span>
                    </a>
                </li>

                <li class="treeview">
                    <a href="{% url 'Dashboard:course' %}">
                       <i class="fa fa-list"></i>
                       <span>Courses</span>
                    </a>
                </li>

                <li>
                    <a href="{% url 'Dashboard:teacher' %}">
                      <i class="fa fa-user"></i>
                      <span>Teachers</span>
                    </a>
                </li>
            </ul>

my urls.py file:

from django.urls import path
from . import views
app_name = 'Dashboard'
urlpatterns = [
    path('', views.IndexView.as_view(), name='index'),
    path('course/', views.course, name='course'),
    path('teacher/', views.teacher, name='teacher'),
    path('student/', views.student, name='student'),
    path('result/', views.result, name='result'),
]

When I change from one page to another nothing happens except teacher page and from teacher page I cannot go any other pages!

Upvotes: 1

Views: 522

Answers (2)

Ines Tlili
Ines Tlili

Reputation: 810

You are not calling the right URLs in your template : It should be like the following :

        <ul class="sidebar-menu" data-widget="tree">
            <li class="treeview">
              <a href="{% url 'Dashboard:index' %}">
               <i class="fa fa-dashboard"></i> <span>Index</span>
              </a>
            </li>

            <li class="treeview">
              <a href="{% url 'Dashboard:course' %}">
                <i class="fa fa-th"></i> <span>Courses</span>
              </a>
            </li>


            <li class="treeview">
              <a href="{% url 'Dashboard:student' %}">
                <i class="fa fa-list"></i><span>Students</span>
              </a>
            </li>

            <li>
              <a href="{% url 'Dashboard:result' %}">
                <i class="fa fa-user"></i> <span>Results</span>
              </a>
            </li>
            <li>
              <a href="{% url 'Dashboard:teacher' %}">
                <i class="fa fa-user"></i> <span>Teachers</span>
              </a>
            </li>
        </ul>

Upvotes: 1

Satevg
Satevg

Reputation: 1601

You should use url template tag

<a href="{% url 'Dashboard:index' %}">

and same for

<a href="{% url 'Dashboard:result' %}">

Upvotes: 1

Related Questions