EMP
EMP

Reputation: 62031

Check whether debug is enabled in a Pylons application

I'm working on a fairly simple Pylons 0.9.7 application. How do I tell, in code, whether or not debugging is enabled? That is, I'm interested in the value of the debug setting under [app:main] in my INI file. More generally, how do I access the other values from there in my code?

Upvotes: 1

Views: 283

Answers (1)

Mark Rushakoff
Mark Rushakoff

Reputation: 258478

# tmp.py
print __debug__


$ python tmp.py
True
$ python -O tmp.py
False

I'm not sure if this holds in Pylons, as I've never used that -- but in "normal" command line Python, debug is enabled if optimizations are not enabled. The -O flag indicates to Python to turn on optimizations.

Actually, there's this snippet from Pylons documentation:

    # Display error documents for 401, 403, 404 status codes (and
    # 500 when debug is disabled)
    if asbool(config['debug']):
        app = StatusCodeRedirect(app)
    else:
        app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

Looks like config['debug'] is what you want.

Upvotes: 3

Related Questions