Python 为什么我的HTTP帖子在flask中不起作用?

Python 为什么我的HTTP帖子在flask中不起作用?,python,python-3.x,http,flask,post,Python,Python 3.x,Http,Flask,Post,我有一个烧瓶应用程序,下面有一个配置文件函数: @app.route('/profile/') def profile(username, password): return f"<h1>username entered: {username} password entered: {password}</h1>" 这是我的index.html文件(仅身体部分) 登录 用户名 密码 提交 然而,当我尝试登录然后提交时,我得到一个TypeErr

我有一个烧瓶应用程序,下面有一个
配置文件
函数:

@app.route('/profile/')
def profile(username, password):
    return f"<h1>username entered: {username} password entered: {password}</h1>"
这是我的
index.html
文件(仅身体部分)

登录
用户名
密码
提交

然而,当我尝试登录然后提交时,我得到一个TypeError,说我的
profile
函数缺少这两个参数。我在终端上打印了我的用户名和密码,所以我知道我的登录功能运行良好。为什么会出现此错误?如何修复此错误?

配置文件函数中的参数应与url参数相对应。您需要更新URL,如下所示:

@app.route('/profile/<string:username>/<string:password>')
def profile(username, password):
    return f"<h1>username: {username} password entered: {password}</h1>

@app.route('/profile/'))
def配置文件(用户名、密码):
返回f“用户名:{username}输入的密码:{password}”
url参数的一个更实际的用途是,例如:获取给定用户id的用户配置文件

@app.route('/profile/<int:userId>', methods=["GET"])
def profile(userId):
    user = getUserById(userId) 
    return f"<h1>username: {user["username"]}. userId: {user["id"]}</h1>
@app.route('/profile/',methods=[“GET”])
def配置文件(用户ID):
user=getUserById(userId)
返回f“username:{user[“username”]}。用户id:{user[“id”]}
从理论上讲,请求如下所示:
GET/profile/20
响应:
username:foo。userId:20

@app.route('/profile/',methods=['GET'])尝试使用此方法。我认为由于没有定义方法类型,路由被弄糊涂了。
@app.route('/profile/<string:username>/<string:password>')
def profile(username, password):
    return f"<h1>username: {username} password entered: {password}</h1>

@app.route('/profile/<int:userId>', methods=["GET"])
def profile(userId):
    user = getUserById(userId) 
    return f"<h1>username: {user["username"]}. userId: {user["id"]}</h1>