Pass argument to flask from javascript
<p>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 these parameters to my flask file and call another function there. How would i accomplish this?</p>

<p>The javascript:</p>

<pre><code>&lt;script&gt;
    function ToPython(FreeSearch,LimitContent)
    {
        alert(FreeSearch);
        alert(LimitContent);
    }
&lt;/script&gt;
</code></pre>

<p>The flask function that i want to call:</p>

<pre><code>@app.route('/list')
def alist(FreeSearch,LimitContent):
    new = FreeSearch+LimitContent;
    return render_template('list.html', title="Projects - " + page_name, new = new)
</code></pre>

<p>I want to do something like <code>"filename.py".alist(FreeSearch,LimitContent)</code> in the javascript but its not possible...</p>

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

<pre><code>/list?freesearch=value1,limit_content=value2
</code></pre>

<p>Then in your function definition:</p>

<pre><code>@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)
</code></pre>

<p>Alternatively, you could use path variables:</p>

<pre><code>/list/value1/value2
</code></pre>

<p>and</p>

<pre><code>@app.route('/list/&lt;freesearch&gt;/&lt;limit_content&gt;')
def alist():
    new = free_search + limit_content
    return render_template('list.html', title="Projects - "+page_name, new=new)
</code></pre>

javascript python flask jinja2