Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
How to send variable data form html to flask

I want to send variable data form html to flask
This is my html js code.
I can not send that variable data to the flask in that way.

<script>
        var data = "shan";
        window.location.href='{{ url_for( "move_forward" , title=data) }}';
</script>

But when I used below way I can send it

<script>
        window.location.href='{{ url_for( "move_forward" , title="shan") }}';
</script>

But finally I want to assign some value to the variable and I want to send it to the flask.
How can I do it

 @app.route("/move_forward/<title>", methods=['GET', 'POST'])
        def move_forward(title):
             print(title)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Jinja templates (the parts using {{ ... }}) are not JavaScript.

When you call render_template, '{{ url_for( "move_forward" , title="shan") }}' gets replaced with something like '/move_forward/shan' and this is what the client receives.

When you do '{{ url_for( "move_forward" , title=data) }}' Flask/Jinja doesn't know what data is because it doesn't interact with the JavaScript, it's just trying to replace a string.

You could instead use a mixture of JavaScript and Jinja to get it working:

<script>
    var baseUrl = '{{ url_for("move_forward") }}';
    var data = "shan";
    window.location.href = baseUrl + "/" + data;
</script>
about 4 years ago · Juan Pablo Isaza Report

0

Thank you @Henry for your answer and I go trough it and do little modification to do it work.

In HTML js script I modify like bellow

var baseUrl = '{{ url_for("move_forward") }}';
var data = "shan";
window.location.href = baseUrl + "?title=" + data;

and Then I modify the Flask code like bellow.

@app.route("/move_forward", methods=['GET', 'POST'])
        def move_forward():
            if request.method == 'GET':
                title = request.args.get('title')

Now it's work perfectly. Thank you

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!