Search code examples
djangodebuggingotree

How can I turn off the debug mode in oTree?


I'm trying to run a web application from Otree (a web platform based on django and Python) in production mode(debug = false). I can't find where the variable OTREE_PRODUCTION is located.


Solution

  • The OTREE_PRODUCTION variable is a system environment variable, meaning it has a scope greater than your Otree project. Because of that, it is more complicated to set. Below is a description of how to do that for Mac or other UNIX systems.

    You can reverse the conditional as the previous answer suggests, but if you actually want to take the experiment live and put it on a remote server like Heroku, this is not advisable. That's because you'll probably need to actually debug and you don't want to have to relaunch (compile on the remote servers) just to do that. If you use the environmental variable correctly, you avoid this problem.

    The following steps work for any Otree related environmental variables, like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, OTREE_AUTH_LEVEL, and OTREE_ADMIN_PASSWORD.

    Setting OTREE_PRODUCTION locally on a Mac:

    All you need to do is modify the .bash_profile file. This tells your terminal general things about how run things in it. It is located in your home directory and is hidden, hence the leading period in the name. Using your text editor of choice, open the file.

    vim ~/.bash_profile
    

    The ~/ specifies that the file is located in your home directory. Inside the file you'll see other lines like the ones below specifying which version of python to run when you call it. Don't change these.

    # Setting PATH for Python 2.7
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    export PATH
    

    All you need to do is add the two lines below and save the file.

    OTREE_PRODUCTION=1
    export OTREE_PRODUCTION
    

    The first line sets the variable to True and the second broadcasts this variable and value out to anything that might use it. A more detailed answer is here.

    For the values to actually be broadcast out, the shell needs to be restarted. You can do that by running source ~/.bash_profile

    Now you can check the value of the variable by running the following command.

    echo $OTREE_PRODUCTION
    

    The $ indicates that the thing to be "echoed" is a variable. Without it, it just returns the same text.

    Setting OTREE_PRODUCTION=1 on Heroku:

    You might not even need to or want to do this locally because you can just tell Heroku to run in production mode while the local version stays in debug. Assuming you are all set up on Heroku, you can run the following command. With this one line, you can toggle back and forth between debug (OTREE_PRODUCTION=0) and production (OTREE_PRODUCTION=1) on your production server.

    heroku config:set OTREE_PRODUCTION=1
    

    You can then view all environmental variables with

    heroku config