栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python+flask基础应用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python+flask基础应用

#!/usr/bin/env python3
# coding: utf-8

from flask import Flask, request, make_response
import json

app = Flask(__name__)


# 只接受get方法访问
@app.route("/getTest", methods=["GET"])
def get_test():
    # 获取URL?后面所有的参数和值
    args = request.args
    name = args.get('name')
    age = int(args.get('age'))
    return "name是%s, age是%d" % (name, age)


@app.route("/postJson", methods=["POST"])
def post_json():
    # 获取json串的值
    body = request.get_data()
    return body


@app.route("/postForm", methods=["POST"])
def post_form():
    # 获取form的参数和值
    test = request.form['test']
    return test


@app.route("/upload", methods=['POST'])
def upload():
    image = request.files.get("image")
    name = request.form.get('name')
    dst_path = "D:/test_demo/test_file/image/%s" % name
    image.save(dst=dst_path)
    res = make_response(dst_path, 200)
    return res


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=12345)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/269237.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号