#EDIT 2 check this answer Here.
I report here the most of it as referance:
- [
request.args
][2]: the key/value pairs in the URL query string
- [
request.form
][3]: the key/value pairs in the body, from a HTML post form, or JavaScript request that isn't JSON encoded
- [
request.files
][4]: the files in the body, which Flask keeps separate from form
. HTML forms must use enctype=multipart/form-data
or files will not be uploaded.
- [
request.values
][5]: combined args
and form
, preferring args
if keys overlap
- [
request.json
][6]: parsed JSON data. The request must have the application/json
content type, or use [request.get_json(force=True)
][7] to ignore the content type.
All of these are [MultiDict
][8] instances (except for json
). You can access values using:
request.form['name']
: use indexing if you know the key exists
request.form.get('name')
: use get
if the key might not exist
request.form.getlist('name')
: use getlist
if the key is sent multiple times and you want a list of values. get
only returns the first value.
First it would be helpful if you also add the flask code. That's being said, add this to the input tag:
<form id='details'method="post">
<input class="myButton" name="details" id="mybutton" type="submit" value="Save"
onclick="getdata()">
</input>
</form>
So basically you had a 'name=""' field to it.
Then in the python file, use this:
request.form['details']
Even better if you store the value in a variable (obviously that's depend you, is just a suggestion)
request_detail = request.form['details']
Also in the form tag you may want to add a 'action=""' field. This depends on how route Decorator in the flask.
Example if you have this:
@app.route('/details)
def details():
pass
Then your form should have this:
<form id='details'method="post" action="/details">
or
<form id='details'method="post" action="details">
EDIT
Try to use a normal route decorator to see if it fixes:
@app.route('/entry1', methods=['GET', 'POST'])
def new_data():
if request.method == 'POST':
details = request.form['details']
print(details)
return render_template('filename.html')
If you still want to use the add_url_rule try this:
app.add_url_rule('/', 'entry1', view_func=new_data, methods=['GET', 'POST'] )