python:Flask轻量级 Web 应用框架

安装使用

 #初始化虚拟python库文件夹
 py -3 -m venv venv
 #激活虚拟库
 venv\Scripts\activate
 #安装Flask
 pip install Flask
 #venv同级目录创建app.py
 #创建templates文件夹,编写index.html页面
 #venv同级cmd启动命令
 venv\Scripts\activate
 flask run

app.py启动程序的编写

 from flask import Flask,render_template
 ​
 app = Flask(__name__)
 ​
 #根目录页面
 @app.route("/")
 def hello_world():
     return "hello,%s"%"世界"#传值
 @app.route("/user/<name>")
 def user(name):
     return "hello,%s"%name
 ​
 #跳转页面,传递数据
 @app.route("/index")
 def main():
     return render_template("index.html",name="李四")
 ​
 if __name__ == '__main__':
     app.run(debug=True)

index.html页面的编写

 <html lang="en">
 <head>
 <meta charset="UTF-8"/>
 <title>Title</title>
 </head>
 <body>
 <p>你好!{{ name }}</p>
 </body>
 </html>

 

 

posted @ 2021-08-29 00:10  你就是我  阅读(90)  评论(0)    收藏  举报