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
	看执行效果
相关推荐
铁蛋AI编程实战几秒前
通义千问 3.5 Turbo GGUF 量化版本地部署教程:4G 显存即可运行,数据永不泄露
java·人工智能·python
jiang_changsheng13 分钟前
RTX 2080 Ti魔改22GB显卡的最优解ComfyUI教程
python·comfyui
0思必得01 小时前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化
沈浩(种子思维作者)1 小时前
系统要活起来就必须开放包容去中心化
人工智能·python·flask·量子计算
2301_790300961 小时前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
m0_736919101 小时前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
getapi1 小时前
实时音视频传输与屏幕共享(投屏)
python
java干货2 小时前
为什么 “File 10“ 排在 “File 2“ 前面?解决文件名排序的终极算法:自然排序
开发语言·python·算法
机器懒得学习2 小时前
智能股票分析系统
python·深度学习·金融
毕设源码-郭学长2 小时前
【开题答辩全过程】以 基于python的二手房数据分析与可视化为例,包含答辩的问题和答案
开发语言·python·数据分析