Ask Your Question
4

What is the method to retrieve information from the second form located in a different root using Python Flask?

asked 2021-08-17 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-04-06 08:00:00 +0000

pufferfish gravatar image

The method to retrieve information from the second form located in a different root using Python Flask is to create a separate route for the second form in the Flask application and then use the request object to retrieve the submitted data from the form.

Here is an example code:

from flask import Flask, request

app = Flask(__name__)

@app.route('/')
def index():
    return "<h1>Hello World!</h1>"

@app.route('/secondform', methods=['GET', 'POST'])
def second_form():
    if request.method == 'POST':
        data = request.form['input_field_name']
        # do something with the data

    return """
        <form method="POST" action="/secondform">
            <input type="text" name="input_field_name" />
            <input type="submit" value="Submit" />
        </form>
    """

if __name__ == '__main__':
    app.run(debug=True)

In this example, the second form is located at the /secondform URL. The second_form function handles this route and retrieves the submitted data using the request.form object. The submitted field is accessed using the name attribute of the input field (in this case, input_field_name).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-17 11:00:00 +0000

Seen: 10 times

Last updated: Apr 06 '23