接到項目需求沛简。需要搭建一個頁面進行交互,慢慢來
b (2).jpg
使用python django框架進行頁面的搭建
在項目文件下打開窗口斥废,輸入命令;
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文件中進行TEMPLATES 項目的配置:
'DIRS': [BASE_DIR+"/templates",], #修改位置
在urls中創(chuàng)建如下配置:
from django.urls import path
from . import view
urlpatterns = [
path('index/', view.hello),
因為已經(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>
簡單的頁面跳轉(zhuǎn)撒顿,制作完成丑罪。最主要的是路由的配置荚板,就是settings里面需要設置的dirs.還有urls里面的路由。