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

325
Views
How to request header in Flask? Or how to get a select option tag's value?

I want to get select value in HTML and use in python Flask. Because I could not find any way to get select tag option value via Flask, I get the value with JavaScript and then span it in a header. Now, I want to request the header but I could not. I get Key Error. Here is my HTML code.

        <label for="filtre_input">Neye göre karşılaştırmak istersiniz?</label>
        <select name="filtre_input" id="filt" onchange="filtreinputla();">
         <option selected="selected">Kategori</option>
         <option value="il">İl</option>
         <option value="tur">Tür</option>
         <option value="renk">Renk</option>
         <option value="duygu">Duygu</option>
       </select>

      <script type="text/javascript">
        function filtreinputla() {
        var filtreselect = document.getElementById("filt").value;
        console.log(filtreselect);
        document.getElementById("filtreselectid").innerHTML = filtreselect;
        }
      </script>
 <h3 id = "filtreselect_p" type = "hidden" name="filtreselect_p"><span id="filtreselectid"></span></h3>

Here is my app.py code.

@app.route("/nd", methods=['POST', 'GET'])
def func():
  flash("")
  filter = request.headers["filtreselect_p"]
  if filter == None:
      flash("Please, select something.")
      return render_template("index.html")
  else:
      result = my_function(filter)
      flash(result)
      return render_template("index.html")

I want to request the header or find a new approach to get select option tag value. Please, help if you can :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use form tag.
You can use GET or POST method.

<form method="get" action="/ng"><--or method="post"-->
<label for="filtre_input">Neye göre karşılaştırmak istersiniz?</label>
        <select name="filtre_input" id="filt" onchange="filtreinputla();">
         <option selected="selected">Kategori</option>
         <option value="il">İl</option>
         <option value="tur">Tür</option>
         <option value="renk">Renk</option>
         <option value="duygu">Duygu</option>
       </select>
</form>

If you use GET method your flask code is

request.args.get('filtre_input')

If you use POST method you can use

request.form.get('filtre_input')
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!