Home >Backend Development >Python Tutorial >How to Send Data from an HTML Form to a Flask Python Script?
Sending Data from HTML Form to Python Script in Flask
In your Python script, you can use Flask to handle data submitted from an HTML form. To pass user input from the "projectFilepath" form field to your script, modify the form and view accordingly.
1. Update HTML Form:
The form in init.html should include attributes and an input name:
<form action="{{ url_for('handle_data') }}" method="post" enctype="multipart/form-data"> <input type="text" name="projectFilepath" placeholder="Spot your project files"> <input type="submit" value="Spot"> </form>
2. Create View to Handle Submitted Data:
In your Python script, add a view called handle_data that handles the POST request and retrieves the form data:
@app.route('/handle_data', methods=['POST']) def handle_data(): project_path = request.form['projectFilepath'] # Your code here
By making these changes, you can pass the user input from the form to your script for further processing.
The above is the detailed content of How to Send Data from an HTML Form to a Flask Python Script?. For more information, please follow other related articles on the PHP Chinese website!