I have a form on my home page that is generated from a list of folders on disk. I can't figure out how to route to the next page and add a dynamic url. So that the url reads http://127.0.0.1:5000/projects/ (http://127.0.0.1:5000/projects/banana) (http://127.0.0.1:5000/projects/apple)
@app.route("/")
def home():
return render_template("home.html", list_projects=list_projects)
@app.route('/', methods=['POST', 'GET'])
def project_select_form():
project_select = request.form['project']
return redirect(url_for("project_page"), project=project_select)
@app.route('/projects/<project>', methods=['POST', 'GET'])
def project_page(project):
return render_template("project_selected.html", project=project)
if __name__ == "__main__":
html
<form method = "POST">
<select id="project" name="project">
{% for x in list_projects %}
<option value="{{ x }}">{{ x }}</option>
{% endfor %}
</select>
<input name="text" type="submit">
</form>
<a href="/projects/{{ x }}">{{ x }}</a>instead of form and options. OR you will have to use JavaScript to changeurlin<form action="url">@app.route('/projects')and send form to this url<form action="/project">and get name fromrequest.form.get("project")