13

How can I activate the Flask debugger when running under mod_wsgi?

I have DEBUG, PROPAGATE_EXCEPTION and PRESERVE_CONTEXT_ON_EXCEPTION set to True, but still the debugger doesn't appear on exceptions.

2 Answers 2

9

As described in the Flask documentation at:

http://flask.pocoo.org/docs/quickstart/#debug-mode

use:

app.debug = True

Under mod_wsgi you aren't doing the app.run() though.

Ensure you are setting 'app.debug' at global scope and not in a conditional section where checking whether __name__ is __main__.

Sign up to request clarification or add additional context in comments.

5 Comments

I just put app.debug = True in my .wsgi file and it still doesn't work. What I found that works is from werkzeug.debug import DebuggedApplication application = DebuggedApplication(app, True).
That is the long handed way of achieving the same. Can't argue with you since you don't actually provide what you actually have in your WSGI file to see what you did when setting app.debug.
From flask.pocoo.org/docs/quickstart/#debug-mode "Even though the interactive debugger does not work in forking environments (which makes it nearly impossible to use on production servers), it still allows the execution of arbitrary code. This makes it a major security risk and therefore it must never be used on production machines." Which to me means that app.debug=True should not work under mod_wsgi by default
Not all execution modes of mod_wsgi are multi process. The default for daemon mode is a single process where the debugger will work fine.
Running my script as CGI on Apache, @jd's solution worked for me while normal app.debug did not
6

You may use interactive debugger provided by werkzeug:

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

This is earley suggested by @jd work for me.

1 Comment

@DanChaltiel after create app variable i.e. after code like app = Flask()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.