Django导航链接不起作用

时间:2018-08-10 14:31:01

标签: django django-templates

当我从一页切换到另一页时,除教师页面外没有任何反应 从老师页面我不能再去其他页面!

            <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>

我的urls.py文件:

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'),
]

当我从一页切换到另一页时,除教师页面外没有任何反应 从老师页面我不能再去其他页面!

2 个答案:

答案 0 :(得分:1)

您应该使用url模板标记

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

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

答案 1 :(得分:1)

您没有在模板中调用正确的URL:它应该类似于以下内容:

        <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>