python使用flask框架实现http服务处理

1,python使用flask框架实现http接口与html的返回

1,py文件同级建立文件夹 templates

2,把html文件放进去 命名为hello.html

html代码

html 复制代码
<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
</head>
<body>
    <h1>Hello, {{ name }}!</h1>
</body>
</html>

python代码

python 复制代码
from flask import Flask, render_template

app = Flask(__name__)


@app.route('/test')
def index():
    return 'Hello, World!Py'


@app.route('/hello/<name>')
def hello(name):
    return render_template('hello.html', name=name+'Py')


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)
复制代码
3,启动后 访问 
	http://127.0.0.1/hello/name
	http://127.0.0.1/hello/test
	看执行效果
相关推荐
Dxy12393102161 天前
python把文件从一个文件复制到另一个文件夹
开发语言·python
sonrisa_1 天前
collections模块
python
折翼的恶魔1 天前
数据分析:排序
python·数据分析·pandas
天雪浪子1 天前
Python入门教程之赋值运算符
开发语言·python
站大爷IP1 天前
5个技巧写出专业Python代码:从新手到进阶的实用指南
python
hrrrrb1 天前
【Python】字符串
java·前端·python
大翻哥哥1 天前
Python 2025:低代码开发与自动化运维的新纪元
运维·python·低代码
Source.Liu1 天前
【Pywinauto库】12.2 pywinauto.element_info 后端内部实施模块
windows·python·自动化
Source.Liu1 天前
【Pywinauto库】12.1 pywinauto.backend 后端内部实施模块
开发语言·windows·python·自动化
用户8356290780511 天前
用Python高效处理Excel数据:Excel数据读取指南
后端·python