Python Flask如何从URL中获取参数? [英] Python Flask how to get parameters from a URL?
本文介绍了Python Flask如何从URL中获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用flask和python从URL中提取命名参数?
当用户访问运行在我的烧瓶应用程序上的这个URL时,我希望Web服务能够处理问号后指定的参数:
http://10.1.1.1:5000/login?username = alex& password = pw1
#我只是想能够操作参数
@ app.route('/ login',methods = ['GET','POST'] )
def login():
username = request.form ['username']
print(username)
password = request.form ['password']
打印(密码)
解决方案
使用 request.args
得到解析的内容的查询字符串:
$ $ p $ from flask import request
@ app.route(...)
def login():
username = request.args.get('username')
password = request.args.get('password')
In Flask, How do I extract parameters from a URL? How can I extract named parameters from a URL using flask and python?
When the user accesses this URL running on my flask app, I want the web service to be able to handle the parameters specified after the question mark:
http://10.1.1.1:5000/login?username=alex&password=pw1
#I just want to be able to manipulate the parameters
@app.route('/login', methods=['GET', 'POST'])
def login():
username = request.form['username']
print(username)
password = request.form['password']
print(password)
解决方案
Use request.args
to get parsed contents of query string:
from flask import request
@app.route(...)
def login():
username = request.args.get('username')
password = request.args.get('password')
这篇关于Python Flask如何从URL中获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文