如何将POST请求转换为GET请求?

2024-04-26 09:20:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我在flask中创建了一个web应用程序,它有一个表单,用户输入的任何文本都会与之前输入的所有消息一起出现在底部。你知道吗

我试图使用JMeter对其进行加载测试,但是我无法使用JMeter中的多个线程发送POST请求,因此我想将POST请求转换为GET请求,以便能够对我的应用程序执行加载测试。你知道吗

现在我的路线是这样的

@app.route('/blog', methods=['GET', 'POST'])
@app.route('/', methods=['GET', 'POST'])
def blog():
print
form = PostForm()
if form.validate_on_submit():
    post = Post(body=form.post.data)
    db.session.add(post)
    db.session.commit()
    return redirect(url_for('blog'))
posts = Post.query.all()
return render_template('index.html', title='Blogger', form=form,
                       posts=posts)

如何通过URL发送参数。你知道吗

我对web开发非常陌生,我在flask中学习了mega教程。有解决办法吗?你知道吗


Tags: formwebapp应用程序flaskdbgetblog
1条回答
网友
1楼 · 发布于 2024-04-26 09:20:34

添加@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

相关问题 更多 >