Hi Graham,
It has been a few days since I installed your modwsgi update with the knob for —ssl-certificate-chain-file some/path/file.crt.
Today, I needed to run "python manage.py collectstatic" and I encountered this error that I hadn't encountered earlier. I get the same error with any python manage.py xxx command.
I've looked at similar issues reported on StackOverflow but those answers did not work/apply in my case.
(vishwaas_env)[syt_admin@VM1 vishwaas_django]$ python manage.py collectstatic
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/home/syt_admin/.virtualenvs/vishwaas_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/home/syt_admin/.virtualenvs/vishwaas_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/syt_admin/.virtualenvs/vishwaas_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 182, in fetch_command
settings.INSTALLED_APPS
File "/home/syt_admin/.virtualenvs/vishwaas_env/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/syt_admin/.virtualenvs/vishwaas_env/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/syt_admin/.virtualenvs/vishwaas_env/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/syt_admin/projects/vishwaas/vishwaas_django/vishwaas_django/settings/production.py", line 19, in <module>
SECRET_KEY = get_secret('SECRET_KEY')
File "/home/syt_admin/projects/vishwaas/vishwaas_django/vishwaas_django/settings/production.py", line 17, in get_secret
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable
Note that launching Django using the Apache script generated by modwsgi works fine and I am able launch and connect to the website.
However, I do notice that my Django logging file is now written in the server-root directory instead of in the django project directory as it was earlier. They are different directories at the same level of nesting.
Here's what I had used to generate the httpd.conf:
(vishwaas_env)[syt_admin@VM1 www-https]$ mod_wsgi-express setup-server ../vishwaas_django/vishwaas_django/wsgi.py --user apache --group apache --server-root=/home/syt_admin/projects/vishwaas/www-https --https-port 443 --port 80 --server-name www.xyz.in --ssl-certificate-file startssl-certs/2_www.xyz.in.crt --ssl-certificate-key-file startssl-certs/server.key --ssl-certificate-chain-file startssl-certs/1_root_bundle.crt --url-alias /static/home/syt_admin/projects/vishwaas/vishwaas_django/collected_static
wsgi.py has the following contents:
import os, sys
sys.path.append('/home/syt_admin/projects/vishwaas/vishwaas_django')
os.environ['DJANGO_SETTINGS_MODULE'] = "vishwaas_django.settings.production"
manage.py has the following contents:
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "vishwaas_django.settings.production")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
production.py has the following contents (relevant snippet):
from .base import *
import json
from django.core.exceptions import ImproperlyConfigured
# JSON-based secrets module located at same level as manage.py
with open(root("secrets.json")) as f:
secrets = json.loads(f.read())
def get_secret(setting, secrets=secrets):
"""Get the secret variable or return explicit exception."""
try:
return secrets[setting]
except KeyError:
error_msg = "Set the {0} environment variable".format(setting)
raise ImproperlyConfigured(error_msg)
SECRET_KEY = get_secret('SECRET_KEY')
where root is defined in settings/base.py as:
here = lambda *dirs: join(abspath(dirname(__file__)), *dirs)
BASE_DIR = here("..", "..")
root = lambda *dirs: join(abspath(BASE_DIR), *dirs)
Any idea what could have gone wrong?
Regards,
Tanuka