0

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>
2
  • What is the problem? Commented Mar 8, 2019 at 22:50
  • when i hit submit on my html, it just opens my python script in my web browser, it doesn't appear to be executing Commented Mar 8, 2019 at 22:57

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

this just returns python code in text i'm a bit confused how to get this working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.