settings.py介绍
简单小实例
from django.shortcuts import render
# Create your views here.
def index(request):
context={
'username':'111'
}
return render(request,'index.html',context=context)
def company(request):
return render(request,'company.html')
def school(request):
return render(request,'school.html')
同时在urls.py中进行配置路由
from django.contrib import admin
from django.urls import path
#引入views
from font import views
urlpatterns = [
path('', views.index,name='index'), #配置路由,并把该路由的名称命名为index
path('company/', views.company,name='company'),
path('school/',views.school, name='school')
在templates文件夹中index.html中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="{% static 'index.css' %}">
</head>
<body>
<header>
<div id="nav">
<div><a href="/">首页</a></div>
<div><a href="{% url 'company' %}">公司</a></div>
<div><a href="{% url 'school' %}">校园</a></div>
</div>
</header>
</body>
</html>
便可实现点击标签跳转的功能