Take the 2-minute tour ×

We need to load different configuration options in our Python WSGI application, according to production or debugging environments (particularly, some server configuration information relating to the task server to which the application needs to post jobs). The way we have implemented it so far is to have a global debug variable that gets set in our deployment script - which does modify the deployment setup correctly. However, when we execute the application, we need to set the debug variable to True - since its default value is False.

So far, it is hard to correctly determine the way the debug variable works, because it is set at deploy time, not execute time. We can set it before calling the serve_forever method of our debug WSGI server, but I am not aware of the implications of this and how good that solution is.

What is the usual pattern for differentiating between debug and production environments in WSGI applications? If I need to pass it in system arguments, or if there is any other, different way, please let me know. Thanks very much!

share|improve this question
And how do you handle your app configuration? The way you want to handle debug should be coherent with your configuration pattern. –  Robert Zaremba Jan 29 '13 at 18:35
add comment

2 Answers

up vote 3 down vote accepted

If your setup allows it, consider using environment variables. Your production servers could have one value for an environment variable while dev servers have another. Then on execution of your application you can detect the value of the environment variable and set "debug" accordingly.

share|improve this answer
+1. That's a very good idea. For now, I've implemented it by checking the command line that was used to execute the script that runs the application, but this is probably a better / more future-proof solution. –  Juan Carlos Coto Jan 17 '13 at 22:02
add comment

I don't like using environment variables. Try to make it working with your application configuration, which can be overwrite by:

  • importing non versioned files (in dev environment), wrapped by try-except with proper log notification.
  • command line arguments (argparse from standard library)
share|improve this answer
add comment

Your Answer


