简体   繁体   中英

How to convert POST request to GET request in flask?

I created a web application in flask that has a form and whatever text the user enters appears on the bottom along with all the previously entered messages.

I was trying to load test it using JMeter, but I'm not able to send POST request using multiple threads in JMeter so I wanted to convert the post request to GET request so that I am able to perform load tests on my application.

Currently my route looks something like this

@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)

What can I do to send the parameters through the URL.

I am very new to web development and I followed the mega tutorial in flask. Is there a workaround this?

add @app.route("/<string:param>",methods['GET']) and give it default values def blog(param = "") and use it for your get method

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM