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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -