Posting JSON and python Flask - any techniques to use the Werkzeug debugger? Posting JSON and python Flask - any techniques to use the Werkzeug debugger? flask flask

Posting JSON and python Flask - any techniques to use the Werkzeug debugger?


Your approach was nearly correct. I am using the following code to open the response text in a new window (not specific to Werkzeug or Flask at all):

var w = window.open('', 'debug_stuff', 'width=540,height=150');w.document.open();w.document.write(response.responseText);w.document.close();

The last line is the most important. Without it, the code would behave as yours -- it would not execute any JavaScript, because the browser doesn't know the DOM has been fully loaded.


Not javascript, but have you tried to use Firebug, you can use the option for viewing the response in a new tab (Open Response in New Tab).


If you're ready to make some changes on both the client and the server code, you can try this. In your error callback you would re-send the JSON data but as a synchonous form submission. You would create the form using jQuery, give it an input tag and put your JSON in that and submit the form. Something like:

$('<form method="post" style="display:none;">')    .attr('action', 'xxx')    .append(        $('<input>').val(JSON.stringify(data))    ).appendTo('body')    .submit();

On the server-side, you would have to accept JSON the regular way when the request's content type is application/json and as form data, eg:

json_string = request.form.get('__json')if json_string:    data = json.loads(json_string)

I have never tried this but I know the problem you're having and it can waste a lot of time. If you try it I'd like to know how it works out.