如何在Flask中将POST请求转换为GET请求?

时间:2019-07-28 08:55:58

标签: python http flask

我在flask中创建了一个具有表单的Web应用程序,用户输入的任何文本都与所有先前输入的消息一起出现在底部。

我试图使用JMeter对其进行负载测试,但是我无法使用JMeter中的多个线程发送POST请求,因此我想将post请求转换为GET请求,以便能够在我的计算机上执行负载测试应用。

当前我的路线看起来像这样

// GIVES CONSOLE.LOG MESSAGE('RUNNING') BUT DOES NOT APPEND SVG
created () {
  console.log("")
  this.add_svg() // append svg for chart
  this.plot([0, 0]) // basic plot with value = [0, 0]
},

...

// SAME METHOD, BUT IN HERE, IT GIVES ME WHAT I WANTED.
// BUT TO INITIALIZE, I WANT TO RUN THE METHOD IN created: part, not in computed
computed () {
  this.add_svg()
  this.plot( datum )
}

...

methods: {
  add_svg: function () {
    console.log("Adding some space for chart")
    d3.select('.chart_test2')
    .append('svg')
      .attr('class', 'svg_chart_test2')
      .attr('width', '10px')
      .attr('height', '10px')
  },
  other methods...
}

如何通过URL发送参数。

我对Web开发非常陌生,我遵循了flask的大型教程。有解决方法吗?

1 个答案:

答案 0 :(得分:1)

添加@app.route("/<string:param>",methods['GET'])并为其提供默认值def blog(param = "")并将其用于您的get方法

@app.route("/<string:param>",methods['GET'])
@app.route("/blog/<string:param>",methods['GET'])
@app.route('/blog', methods=['GET', 'POST'])
@app.route('/', methods=['GET', 'POST'])
def blog(param = ""):
    print
    if request.method == "POST":
        ##your post code here
    elif request.method == "GET":
        ## new code using 'param' here