rubyman rubyman - 1 year ago 122
Python Question

Start Django with different setting values

I am writing test for my Django app. I want to start Django with different settings value and run tests for each case. (eg one test for settings.ALLOW_ROBOTS=True and another test for settings.ALLOW_ROBOTS=False). I am not interested in overriding the value at run time. I want to start the server with different settings value each time. Does Django provide a way to accomplish this?

Answer Source

You can choose which file to use with DJANGO_SETTINGS_MODULE; you can have many that import * from a main one, and then change what needs to be changed.

Alternatively, is just a Python file. You can get values of settings from environment variables, if you want:

import os

ALLOW_ROBOTS = bool(os.getenv('ALLOW_ROBOTS', False))

And then change that environment variable from Travis.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download