rubyman
rubyman

Reputation: 265

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?

Upvotes: 0

Views: 97

Answers (2)

RemcoGerlich
RemcoGerlich

Reputation: 31270

You can choose which settings.py 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, settings.py 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.

Upvotes: 1

zsepi
zsepi

Reputation: 1662

If I understand your question correctly, you would like to be able to use multiple settings modules. If so, setting the DJANGO_SETTINGS_MODULE environment variable before starting the server is likely what you need.

Upvotes: 0

Related Questions