在 django 中从视图加载 url 和 url 时出现问题

having problem loading url from the views and url in django

我正在使用 GitHub 中免费提供的自定义 bootstrap 模板构建网页。我试图将 Django 连接到后端。我在使用 url 和视图时遇到问题。我已经完美地提到了,但我找不到页面。

urls.py 文件

from django.urls import path, include
from django.conf.urls.static import static
from . import views
urlpatterns = [
    path('', views.homepage, name='homepage'),
    path('publications', views.publications, name='publications'),
    path('alumni', views.alumni, name='alumni'),
    path('contact', views.contact, name='contact'),
    path('joinus', views.joinus, name='joinus'),
    path('phdstudents', views.phdstudents, name='phdstudents'),
    path('pi', views.pi, name='pi'),
    path('project1', views.project1, name='project1'),
    path('research', views.research, name='research'),
    path('researchers',views.researchers, name='researchers'),
    path('shiladit', views.shiladit, name='shiladit'),
    path('students', views.students, name='students'),
    path('team', views.students, name='team'),
]

views.py

from django.shortcuts import render
def homepage(request):
    return render(request, 'lab/index.html')
def publications(request):
    return render(request, 'lab/publications.html')
def alumni(request):
    return render(request, 'lab/alumni.html')
def contact(request):
    return render(request, 'lab/contact.html')
def joinus(request):
    return render(request, 'joinus.html')
def phdstudents(request):
    return render(request, 'phd_students.html')
def pi(request):
    return render(request, 'lab/pi.html')
def project1(request):
    return render(request, 'lab/project1.html')
def publications(request):
    return render(request, 'lab/publications.html')
def research(request):
    return render(request, 'lab/research.html')
def researchers(request):
    return render(request, 'researchers.html')

当我点击导航栏重定向页面时出现错误。但是当我给出 url 时,它正在加载如何纠正这个问题。


*在模板中(Html):*
  • 移除

<ul>
  <li><a href="research.html">Research</a></li>
</ul>

  • 试试这个:

    <ul>
      <li><a href="/research/">Research</a></li>
    </ul>