Requests in flask for fields with the same name

Asked

Viewed 20 times

0

  <div>
        {% if filmes|length > 0 %}
        {% for f in filmes %}
        <form action="/pesquisa_filmes_id", method="POST">
            <input type="hidden" id="id_filme", name="id_filme" ,value="{{f}}"> 
            <button class="btn btn-primary" type="submit">{{f}}</button>
        </form>
        {% endfor %}
        {% endif %}
    </div>
def pesquisa_filmes_id():
    api_key = 'xxxxxxx'
    id_filme = request.form['id_filme']
    url = "http://www.omdbapi.com/?apikey={}&i={}".format(api_key, id_filme)
    retorno_id = requests.get(url).json()
    titulo = id_filme
    diretor = 0
    ano = 0
    url_image = "http://img.omdbapi.com/?apikey={0}&i={1}".format(api_key, id_filme)

    return render_template("filme.html", filme = titulo, diretor = diretor, ano = ano, imagem = url_image)

Wanted to return the value of a POST, but as they end up with the same name, at the time of assigning in flask, ends up returning me the empty variable. How could I do that?

  • Apparently your code is ok, does it show any errors? Did you correctly set the POST on your route? ex: @app.route('/search_filmes_id', methods=['POST']) ?

  • My error was in the HTML input, in the comma before the value. .

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.