Brett
Brett

Reputation: 3316

Flask Debugger not working under Windows

I am a newbie to Python attempting to experiment with sample code under Windows 8.1.

On http://flask.pocoo.org/docs/0.10/quickstart/ it says "if you enable debug support the server will reload itself on code changes, and it will also provide you with a helpful debugger".

I have added to the code app.run(debug=True) to the sample code on the above page. The server will now reload itself on code changes (as promised) but when I create a syntax error the "helpful debugger" does not show. Instead I get an error message in my command prompt.

Any ideas why? I suspect the answer might be here Can't enable debug mode in Flask but it is largely uninteligible to me.

So far I have tried restarting my machine and putting the code in different locations. I am not in a forked environment (as best as I know). For those that are curious my source code is shown below:

from flask import Flask
app = Flask(__name__)

from werkzeug.debug import DebuggedApplication
app.wsgi_app = DebuggedApplication(app.wsgi_app, True)

@app.route('/')
def hello_world():
    return 'Hello World! #note the deliberate syntax error


if __name__ == '__main__':
    app.debug = True
    app.run()

Upvotes: 0

Views: 1304

Answers (2)

brytebee
brytebee

Reputation: 90

For Windows users

The page and resource that was selected as the answer in this post led to a broken page. However, try the code below.

Set debug mode using

$env:FLASK_ENV = "development"

Run app

flask run

This post solved it for me

Or

Set it directly from the app in your code.

if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=3000)

Upvotes: 0

bsa
bsa

Reputation: 2801

The debugger is for debugging exceptions in a syntactically valid program. Try raising an exception in your code, visit the URL in a browser window, and you will see the very helpful debugger. See also http://flask.pocoo.org/snippets/21/

Syntax errors will be shown on the console as you have seen. That's how it works.

Upvotes: 1

Related Questions