upload py file using flask

# Step 1: Import necessary modules
from flask import Flask, render_template, request

# Step 2: Create a Flask web application
app = Flask(__name__)

# Step 3: Define a route to handle file upload
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        # Step 4: Check if the POST request has the file part
        if 'file' not in request.files:
            return 'No file part'

        file = request.files['file']

        # Step 5: Check if the file is selected
        if file.filename == '':
            return 'No selected file'

        # Step 6: Save the uploaded file

        # Step 7: Return a success message
        return 'File uploaded successfully'

    # Step 8: Render the file upload form on GET request
    return render_template('upload.html')

# Step 9: Run the Flask application
if __name__ == '__main__':
<!-- Step 10: Create an HTML template for file upload form (upload.html) -->
<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <title>File Upload</title>
    <h1>File Upload</h1>
    <form method=post enctype=multipart/form-data>
      <input type=file name=file>
      <input type=submit value=Upload>