zoukankan      html  css  js  c++  java
  • 使用flask编写简单的mock

    pip install flask  安装flask框架

    from flask import flask,request,json,make_response

    app = flask(__name__)  实例化一个web应用

    @app.route('/', methods=['post'])  通过应用的route装饰器函数编写一个接口路径,  被装饰的函数时此路径的逻辑处理接口

    def hello():

    1、  resp = make_response('hello,world',200) make_response实例化传入两个参数,一个是返回体,一个是返回码

     resp.header['xxxx']='xxx' 设置返回的header

     return resp 返回数据

    2、处理数据

      res1=request.form()获取路径传送的 表单数据

      res2=request.get_dict()获取路径传送来的二进制数据

      json.loads(res2) 将获取的二进制数据装换为python数据对象

      print('hello,word')

    3、直接返回数据,code,header

      return 'xxx',200,{'xxx':'xxx'=xxxx}

    app.run('127.0.0.1',9000)启动这个web应用并赋予地址

  • 相关阅读:
    vue系列——数据请求
    优化记录
    优化记录
    正则
    跨域问题
    原型链之prototype/__proto__/constructor
    vue系列——组件数据通讯(二)
    vue系列——组件数据通讯(一)
    ES6(一)
    ES5总结
  • 原文地址:https://www.cnblogs.com/ceshizhilu/p/14170982.html
Copyright © 2011-2022 走看看