To create an HTML form using Python, you can use the Flask web framework. Here's an example:

  1. Install Flask using pip:
pip install Flask
  1. Create a new Python file called app.py and add the following code:
from flask import Flask, render_template, request

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('form.html')

@app.route('/submit', methods=['POST'])
def submit():
    name = request.form['name']
    email = request.form['email']
    message = request.form['message']
    return f"Name: {name}, Email: {email}, Message: {message}"

if __name__ == '__main__':
    app.run(debug=True)
  1. Create a new HTML file called form.html and add the following code:
<!DOCTYPE html>
<html>
<head>
    <title>HTML Form Example</title>
</head>
<body>
    <h1>HTML Form Example</h1>
    <form action="/submit" method="POST">
        <label>Name:</label>
        <input type="text" name="name"><br><br>
        <label>Email:</label>
        <input type="email" name="email"><br><br>
        <label>Message:</label>
        <textarea name="message"></textarea><br><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>
  1. Run the Python file using the command python app.py and go to http://localhost:5000 in your web browser. You should see the HTML form.

  2. Enter some values in the form and click the "Submit" button. You should see a new page that displays the values you entered.

Html form python coding

原文地址: http://www.cveoy.top/t/topic/frh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录