|
html
- <!DOCTYPE html>
- <html>
- <head>
- <title>Flask Button Example</title>
- </head>
- <body>
- <h1>{{ message }}</h1>
- <form method="POST">
- <input type="text" name="user_field" placeholder="Enter something">
- <button type="submit" name="submit_button" value="Submit">Submit</button>
- </form>
- </body>
- </html>
複製代碼
python
- @app.route('/', methods=['GET', 'POST'])
- def index():
- if request.method == 'POST':
- if 'submit_button' in request.form: # Check if a specific button was clicked
- user_input = request.form.get('user_field')
- processed_message = f"You submitted: {user_input}"
- return render_template('index.html', message=processed_message)
- # ...
複製代碼
|
|