接到項(xiàng)目需求。需要搭建一個(gè)頁(yè)面進(jìn)行交互,慢慢來(lái)

b (2).jpg
使用python django框架進(jìn)行頁(yè)面的搭建
在項(xiàng)目文件下打開(kāi)窗口,輸入命令;
django-admin startproject helloword
#在文件helloword/helloword/創(chuàng)建view.py
在view.py文件中輸入以代碼
from django.shortcuts import render
def hello(request):
context = {}
context['hello'] = '終端集成控制系統(tǒng)'
return render(request, 'index.html', context)
在settings文件中進(jìn)行TEMPLATES 項(xiàng)目的配置:
'DIRS': [BASE_DIR+"/templates",], #修改位置
在urls中創(chuàng)建如下配置:
from django.urls import path
from . import view
urlpatterns = [
path('index/', view.hello),
因?yàn)橐呀?jīng)配置完成了dirs,所以需要在helloword文件夾下。創(chuàng)建templates文件
在此文件夾下,創(chuàng)建index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ hello }}</title>
</head>
<body>
<h1>{{ hello}}</h1>
</body>
</html>
簡(jiǎn)單的頁(yè)面跳轉(zhuǎn),制作完成。最主要的是路由的配置,就是settings里面需要設(shè)置的dirs.還有urls里面的路由。