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.

GileBrt
  • 1,830
  • 3
  • 20
  • 28
jd.
  • 10,678
  • 3
  • 46
  • 55

2 Answers2

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__.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • 9
    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)`. – jd. May 13 '12 at 05:38
  • 1
    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. – Graham Dumpleton May 13 '12 at 06:46
  • 1
    From http://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 – kerma Feb 05 '13 at 10:59
  • 2
    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. – Graham Dumpleton Feb 06 '13 at 02:54
  • 1
    Running my script as CGI on Apache, @jd's solution worked for me while normal app.debug did not – Yuvi Jun 02 '13 at 09:49
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.

Vitold S.
  • 402
  • 4
  • 13