Pass argument to flask from javascript

后端 未结 1 1036
轻奢々
轻奢々 2021-01-14 08:03

When pressing a button i call a javascript function in my html file which takes two strings as parameters (from input fields). When the function is called i want to pass the

相关标签:
1条回答
  • 2021-01-14 08:43

    From JS code, call (using GET method) the URL to your flask route, passing parameters as query args:

    /list?freesearch=value1&limit_content=value2
    

    Then in your function definition:

    @app.route('/list')
    def alist():
        freesearch = request.args.get('freesearch')
        limitcontent = request.args.get('limit_content')
        new = freesearch + limitcontent
        return render_template('list.html', title="Projects - "+page_name, new=new)
    

    Alternatively, you could use path variables:

    /list/value1/value2
    

    and

    @app.route('/list/<freesearch>/<limit_content>')
    def alist():
        new = free_search + limit_content
        return render_template('list.html', title="Projects - "+page_name, new=new)
    
    0 讨论(0)
提交回复
热议问题