I am working on a Flask project that has a simple page which gets input from the users and returns back an output. I am trying to see if I can get a dynamic URL for the web page. Given below are my form and route for this web page:
Form
<form action=""enctype="multipart/form-data"
method="POST">
{{form.hidden_tag()}}
<table>
{{ render_field(form.name, size=50) }}
<tr class="submit">
<td>
<button type="submit">Report</button>
</td>
</tr>
</table>
Views
@app.route('/users', methods=['GET', 'POST'])
def users():
form = UsersForm()
if form.validate_on_submit():
output = user(name=form.name.data)
return send_file(output, attachment_filename = f'UserReport_{name}.csv', as_attachment=True)
return render_template('name', form=form)
The above works just fine.
Page URL is www.website.com/name
I however am trying to see if I can have the webpage URL set to change dynamically based on the value entered in the form (name
field). For example, if name is person1
, I would like to have the URL set to www.website.com/name/person1