Flask render form values -
i have question rendering form results. when submit form want show term below form. did wrong ?
now wehen submit form 200 status code , no error message. term dosent show in defined place.
# app.py @app.route('/search') def search(): return render_template('search/index.html') @app.route('/search<q>') def results(q): return render_template('search/index.html', term=q) # search/index.html {% extends 'base.html' %} {% block content %} <div> <form method="get" action=""> <input type="text" name="q" id=""> <input type="submit"> </form> {{ term }} </div> {% endblock %}
you have confused path parameters (which flask routes parse out , pass view) query parameters (which available in request.args). remove second route , update first access query.
from flask import request @app.route('/search') def search(): term = request.args.get('q') return render_template('search.html', term=term)
Comments
Post a Comment