Hello-flask application has an error


I’m new to Python and Flask so I choose this app to do some learning and it seems that there is an error in this app. It adds a dream to a local ‘ul’ HTML element and also calls the Python /dreams route to put the dream into DREAMS list. This unfortunately does not work correctly. The problem is in spelling:

$.post('/dreams?' + $.param({dream: dream}), function() {

The above creates a parameter “dream” which can be seen in debugger:

ImmutableMultiDict([('dream', u'flying car')])

But the Python code is actually looking for ‘dreams’ parameter:

   if 'dreams' in request.args:

As a result, the dream is never added to the DREAMS list. This error is hidden due to the dream being added to the ‘ul’ HTML list using JavaScript.

The fix is to modify the Python code to say:

   if 'dream' in request.args:

JavaScript should also be fixed to quote the key param like so:

$.post('/dreams?' + $.param({'dream': dream}), function() {


Thanks dmossakowski, updated!