Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
How to take a variable from inside a html form that wasn't inputted by the user and output it to flask app?

<form action="{{ url_for('searchResult') }}" method="POST">
                          <ul style="margin-bottom: 10px;" class="list-group list-group-flush">
                            <li class="list-group-item"><input type="hidden" value="location"/> {{row[0]}}</li>
                            <li class="list-group-item">Capacity :{{row[1]}}</li>
                            <li class="list-group-item">Prices per night(in GBP):</li>
                            <li class="list-group-item">Off-Peak - {{row[2]}}</li>
                            <li class="list-group-item">Peak (Apr-Sept) - {{row[3]}}</li>
                            <li class="list-group-item"><input type="submit" value="More Info"class="btn btn-outline-info"/><input type="submit" class="btn btn-outline-success" value="Book"/></li>
                          </ul>
                        </form>

    @app.route('/Locations', methods=['GET', 'POST'])
def searchResult():
    if request.method == 'POST':
        locationInput = request.form['location']
        searchedLocation = locationInput.capitalize()
        try:       
            conn = connection.connection()
            if conn != None:    #Checking if connection is None    
                print('MySQL Connection is established')                          
                cursor = conn.cursor()    #Creating cursor object
                cursor.execute('USE {};'.format(DB_NAME)) #use database                
                sqlStatement = "SELECT * FROM locations;"
                cursor.execute(sqlStatement)
                rows = cursor.fetchall()
                cursor.close() 
                match = False
                for row in rows:
                    if row[0] == searchedLocation:
                        match = True
                        return render_template('locations/' + searchedLocation + '.html')
                if match == False:
                    return render_template('searchError.html', searchedLocation = searchedLocation)                                    
        except:
            conn.rollback()

When I hit one of the submit buttons I want to take the value of row[0] out into a flask app. The row values have come from an 3d array from the flask app, this block of html is looped over the columns. I want to receive the value of the location for that specific block that I clicked the submit button on so that I can move to a new page specifically about that location, and I don't want to user to see an input box. I'm confused and any help would be much appreciated, thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are several things wrong with this. First, a "hidden" item is not going to be visible, so it should not have a list item (unless you want the user to see it). Second, if you want the hidden item to be called "location", then it's NAME needs to be location. The value is what you want sent back. So:

 <input type="hidden" name"location" value="{{row[0]}}">
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda