python实现Flask GET Demo

python代码

python 复制代码
from flask import Flask, request, jsonify

app = Flask(__name__)

#用/data路径路由
@app.route('/data')
def get_data():
    ## 以下一行是从URL中获取参数的get方法
	data = request.args.get('data')
	return jsonify(
		data = data,
		info = "success !",
		code = "200"
)

if __name__ == '__main__':
	app.debug = True
	app.run(host='192.111.111.111', port=5555)
	# app.run()

get方法可以不需要任何前端代码,直接运行以上Python代码,控制端会有以下输出

bash 复制代码
 * Serving Flask app 'flask_service'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 631-444-681

http://127.0.0.1:5000为我们的URL,因为我们做了/data的路由,所以在浏览器地址栏输入http://127.0.0.1:5000/data?data=2013.9

页面可以返回python文件中设定的json格式数据:

bash 复制代码
{
  "code": "200",
  "data": "2013.4.4",
  "info": "success !"
}
相关推荐
金銀銅鐵18 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup111 天前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi001 天前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 天前
Agent 流程编排
后端·python·agent
copyer_xyf1 天前
Agent RAG
后端·python·agent
copyer_xyf1 天前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf1 天前
Agent 记忆管理
后端·python·agent
星云穿梭2 天前
用Python写一个带图形界面的学生管理系统——完整教程
python