Home > Backend Development > Python Tutorial > How to Send Data from an HTML Form to a Flask Python Script?

How to Send Data from an HTML Form to a Flask Python Script?

Patricia Arquette
Release: 2024-12-21 06:02:12
Original
502 people have browsed it

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>
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template