[英]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. 我在flask中创建了一个具有表单的Web应用程序,并且用户输入的任何文本都会与所有先前输入的消息一起出现在底部。
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. 我试图使用JMeter对其进行负载测试,但是无法在JMeter中使用多个线程发送POST请求,因此我想将Post请求转换为GET请求,以便能够对应用程序执行负载测试。
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. 如何通过URL发送参数。
I am very new to web development and I followed the mega tutorial in flask. 我对Web开发非常陌生,我遵循了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'])
并为其提供默认值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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.