Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

332
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda