Reputation: 93
Task:
User types into a form a char e.g. "hello".
this should be send as an post requests to python, because it is later analyzed via a python script
here is my server side code:
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def result():
print(request.form['foo']) # should display 'bar'
return 'Received !' # response to your request.
if __name__ == '__main__':
app.run()
My html code:
<input class="input-text-input" type="text" placeholder="values" name="website">
How can i get the user input from the php form? What would be the best way? The examples in the internet etc. are overloaded. Maybe i have a general mistake.
Upvotes: 0
Views: 746
Reputation: 38502
To make a request from html form to your python flask API, you can do it this way,
HTML FORM
<form action="{{ url_for('addWebsiteUrl') }}" method="post">
<input class="input-text-input" type="text" placeholder="values" name="website">
<input type="submit" value="Submit">
</form>
FLASK API:
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def result():
print(request.form['website']) # should display 'website'
return 'Received !' # response to your request.
if __name__ == '__main__':
app.run()
Upvotes: 1