0

I run the following code from within my HTML page with Javascript:

$.post(url,{'key':'Value'})

The Python Flask code looks like this:

@main.route('/documents', methods=['GET', 'POST'])
def documents():
    if request.method == 'POST':
        print "Post Recieved"
        jsData = request.get_json(force=True)
        print 'data: ', jsData
        return "<html>Post Recieved</html>"

The output looks like this:

>>Post Received
>>

I find this odd because I should see the console print a 'data: Something' or an error.

When I change the the code to include the following:

jsData = request.get_json(force=False)

I get the following output:

>>Post Received
>>data: None

In this case 'None' refers to a python 'NoneType'.

Bottom line is that I'm having trouble posting the JSON to Python Flask and making the JSON accessible from within Flask. Any help would be appreciated.

ForgottenKahz
  • 268
  • 3
  • 24
  • according to [this post](http://stackoverflow.com/questions/32550487/how-to-print-from-flask-app-route-to-python-console) Flask does not print out simple prints in the python console. Can you change that print into `print(data, js_data, file=sys.stderr)`? – hansaplast Jan 22 '17 at 06:24
  • since you're on python 2 you need to do a `from __future__ import print_function` first before doing that print to stderr – hansaplast Jan 22 '17 at 06:28

0 Answers0