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
	看执行效果
相关推荐
爱笑的眼睛117 分钟前
深入理解MongoDB PyMongo API:从基础到高级实战
java·人工智能·python·ai
辣椒酱.14 分钟前
jupyter相关
python·jupyter
郝学胜-神的一滴17 分钟前
Python中常见的内置类型
开发语言·python·程序人生·个人开发
火白学安全1 小时前
《Python红队攻防零基础脚本编写:进阶篇(一)》
开发语言·python·安全·web安全·网络安全·系统安全
FreeCode1 小时前
LangGraph1.0智能体开发:运行时系统
python·langchain·agent
青瓷程序设计1 小时前
植物识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
习习.y2 小时前
关于python中的面向对象
开发语言·python
hmbbcsm2 小时前
练习python题目小记(六)
开发语言·python
wow_DG2 小时前
【Python✨】VS Code 秒开 Python 类型检查:一招 mypy + settings.json 让你的 Bug 原地现形!
python·json·bug
Aspect of twilight2 小时前
LeetCode华为大模型岗刷题
python·leetcode·华为·力扣·算法题