【发布时间】:2021-11-25 11:11:37
【问题描述】:
我正在使用 GitHub 中免费提供的自定义引导模板构建网页。我试图将 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 是
http://127.0.01:8000/research(没有/index.html),这就是你的urls.py中的内容。导航栏模板如何生成链接? -
你检查过
http://127.0.01:8000/lab/research.html吗? -
感谢您指出@IainShelvington 我没有在导航栏模板中删除
.html。
标签: python django django-views django-urls