mardi 21 août 2018

how can i use url_for function in forms to get the username from input field in to my url?

I want to get the "username" from the input field and put it in my url_for function to build a dynamic route for a user when he logs in. At the moment i am using url_for('function',username="username"). It always redirects me to a url with /username. I want the value passed in by the user to be shown instead. This is my code for forms:

`<form action="" method="post">
<input  type="text" name="username" placeholder="Name" >
<input type="password" name="password" placeholder="password">
<button type="submit"> Submit </button>
</form>`

I want the value of 'name' field in the 'username' This is routing function:

@app.route("/<username>", methods=['post'])
def profile(username):
username = request.form.get("username")
password = request.form.get("password")
return render_template("layout.html",username=username,password=password)




Aucun commentaire:

Enregistrer un commentaire