1.新建Flask項目。
2.設置調試模式。
3.理解Flask項目主程序。
4.使用裝飾器,設置路徑與函數之間的關系。
5.使用Flask中render_template,用不同的路徑,返回首頁、登錄員、注冊頁。
6.用視圖函數反轉得到URL,{{url_for(‘login’)}},完成導航條里的鏈接。
from flask import Flask,render_templateapp = Flask(__name__)@app.route('/') def index():return render_template('index.html')@app.route('/login') def login():return render_template('login.html')@app.route('/regist') def regist():return render_template('regist.html')if __name__ == '__main__':app.run(debug='True')
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>MIS問答平臺</title><style type="text/css">a{font:"宋體";color:LightSkyBlue;font-size:150% }p{color:blue;}.h1{background-color: purple;}.textblue{color:pink;}#tt{ color:yellow;} </style><link href="wk1.2.css"rel="stylesheet"type="text/css"></head> <body> <nav><img src="https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/whfpf%3D180%2C140%2C50/sign=9f84efaedc2a60595245b25a4e0905a3/8718367adab44aede0f8bd83b81c8701a18bfb27.jpg"><input type="text"name="search"><button type="submit">搜索</button><li><a href="{{ url_for('index') }}">首頁</a></li> <li><a href="{{ url_for('login') }}">登陸</a></li> <li><a href="{{ url_for('regist') }}">注冊</a></li> </nav> <div><h1>通知</h1><p>明天早上九點將召開<span style="font-size: 45px;font: 500;background-color:pink";>十九大</span></p><p class="textblue">明天早上九點將召開十九大</p><p id="tt">明天早上九點將召開十九大</p> </div><body>