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_56785 小时前
Selenium+Python可通过 元素定位→操作模拟→断言验证 三步实现Web自动化测试
服务器·人工智能·python
蒜香拿铁6 小时前
【第三章】python算数运算符
python
52Hz1187 小时前
力扣73.矩阵置零、54.螺旋矩阵、48.旋转图像
python·算法·leetcode·矩阵
weixin_462446238 小时前
Python 使用 openpyxl 从 URL 读取 Excel 并获取 Sheet 及单元格样式信息
python·excel·openpyxl
毕设源码-钟学长9 小时前
【开题答辩全过程】以 基于Python的健康食谱规划系统的设计与实现为例,包含答辩的问题和答案
开发语言·python
百***78759 小时前
Grok-4.1技术深度解析:双版本架构突破与Python API快速集成指南
大数据·python·架构
码农水水9 小时前
京东Java面试被问:HTTP/2的多路复用和头部压缩实现
java·开发语言·分布式·http·面试·php·wpf
2501_9421917710 小时前
基于YOLO11-HSFPN的数字检测与识别模型实现详解
python
忧郁的橙子.11 小时前
26期_01_Pyhton基本语法
python
sunfove11 小时前
实战篇:用 Python 徒手实现模拟退火算法解决 TSP 问题
开发语言·python·模拟退火算法