Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

how to pass variables from a html form python flask

from flask import request

@app.route('/py', methods=['GET', 'POST'])
def server():
    if request.method == 'POST':
        # Then get the data from the form
        tag = request.form['tag']

        # Get the username/password associated with this tag
        user, password = tag_lookup(tag)

        # Generate just a boring response
        return 'The credentials for %s are %s and %s' % (tag, user, password) 
        # Or you could have a custom template for displaying the info
        # return render_template('asset_information.html',
        #                        username=user, 
        #                        password=password)

    # Otherwise this was a normal GET request
    else:   
        return render_template('main.html')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pass #variables #html #form #python #flask
ADD COMMENT
Topic
Name
1+3 =