Skip to content

Commit 65f20ca

Browse files
committed
Backported code for specifying settings file from OpenMalaria portal
1 parent 27e8b35 commit 65f20ca

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ apache/static/*
7272

7373
# Sphinx documentation
7474
docs/build/
75+
76+
config_local.py

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,34 @@ DATABASES = {
8989
}
9090
```
9191

92-
# Production deployment checklist
92+
# Specifying settings file
93+
94+
0. By default, website.settings.dev is used for manage.py and website.settings.prod is used in wsgi.py
95+
It is typically required to change default settings file used in manage.py in production and qa enviroments
96+
97+
1. Exporting DJANGO_SETTINGS_MODULE variable
98+
99+
This method works well on the command line, but it doesn't seem to work with apache - SetEnv doesn't seem to have any effect when mod_wsgi
100+
is initalizing wsgi application object.
101+
102+
2. Creating config_local.py in the root folder (next to wsgi.py and manage.py)
103+
104+
Note if DJANGO_SETTINGS_MODULE is defined, it takes precedence over settings_module in config_local.py
93105

94-
1. Change database to PostgreSQL in settings_local.py
106+
Example:
107+
```python
108+
settings_module = "website.settings.qa"
109+
```
110+
Check wsgi.py and manage.py to see how it works - they are different from default versions generated by Django.
111+
112+
113+
# Production deployment checklist
95114

96-
2. Set DEBUG to False in settings_local.py
115+
1. Copy config_local_example.py to config_local.py
97116

98-
3. Generate new SECRET_KEY
99-
100-
4. Change ALLOWED_HOSTS and ADMINS accordingly
117+
2. Generate new SECRET_KEY in settings_local.py
101118

102-
5. Set APP_ENV to 'production'
119+
3. Enable VecNet SSO
103120

104121
# Enable VecNet SSO
105122

config_local_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
settings_module = "website.settings.prod"

manage.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/usr/bin/env python
22
import os
33
import sys
4+
try:
5+
from config_local import settings_module
6+
settings_module_message = "as defined in config_local.py file. DJANGO_SETTINGS_MODULE is ignored."
7+
except ImportError:
8+
settings_module = "website.settings.dev"
9+
settings_module_message = ""
410

511
if __name__ == "__main__":
6-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings.dev")
12+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
713

814
from django.core.management import execute_from_command_line
9-
10-
execute_from_command_line(sys.argv)
15+
print("manage.py: Using settings: %s %s" % (os.environ.get("DJANGO_SETTINGS_MODULE"), settings_module_message))
16+
execute_from_command_line(sys.argv)

wsgi.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
88
"""
99

10+
1011
import os
1112

1213
from django.core.wsgi import get_wsgi_application
1314

14-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings.prod")
15+
try:
16+
from config_local import settings_module
17+
except ImportError:
18+
settings_module = "website.settings.prod"
19+
20+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
1521

1622
application = get_wsgi_application()

0 commit comments

Comments
 (0)