Reputation: 148
I am trying to pass my html form data to python using flask, however I'm not 100% sure where I'm going wrong
Python
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('home.html')
@app.route('/form', methods = ['GET', 'POST'])
def form():
your_name = request.form['your_name']
customer_number = request.form['customer_number']
msg = request.form['msg']
if __name__ == '__main__':
app.run()
This my from from HTML
<form action="smssend.py" method="post">
<label for="msg">Message</label>
<textarea id="msg" name="msg" rows="5" cols="50"> </textarea> <br>
<label for="your_name">Your Name:</label>
<input type="text" name="your_name" id="your_name" /> <br>
<label for="customer_number">Customers Number:</label>
<input type="text" name="customer_number" id="customer_number" /> <br>
<input type="submit">
</form>
Upvotes: 0
Views: 2159
Reputation: 169
You need to change the action to the URL that handles the request like this:
<form action="http://localhost:8000/form" method="post"> ... </form>
ofc change the URL according to your setup.
Upvotes: 1