Can't retrieve variable from url with Flask app after submitting search form

后端 未结 2 1177
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 01:43

I would like to present a new view after the user submits a search form. I made it as the same way as I do with my other views, but unfortunately this time doesn\'t happens

2条回答
  •  一个人的身影
    2020-12-02 02:18

    You're confusing url parameters, which are captured with , with query parameters, which are accessed in request.args. Remove the query parameter from your route definition and access it in the view.

    from flask import request
    
    @app.route('/')
    def index():
        return render_template('index.html')
    
    @app.route('/search')
    def search():
        search = request.args.get('search')  # will be None if form wasn't submitted
        # do something with search
        return render_template('search.html', search=search)
    

    index.html:

提交回复
热议问题