Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
Declare Django settings to use with mod_wsgi/apache

I have multiple settings files in my Django project (base.py, local.py, production.py).

Locally, I'm kicking off the Django dev server via

python manage.py runserver --settings=config.settings.local

How can I tell mod_wsgi to use the same file? I'm testing this on my local apache instance, but will need to figure out the same thing for my production apache instance.

--settings=config.settings.production

Current httpd-vhosts.conf:

WSGIDaemonProcess secureDash python-path=/Users/user/projects/secureDash_project/secureDash python-home=/Users/user/.venvs/securedash_py3.6
WSGIProcessGroup secureDash
WSGIScriptAlias / /Users/user/projects/secureDash_project/config/wsgi.py

Error that I see in the apache log:

ModuleNotFoundError: No module named 'secureDash.settings'

Django 1.11

mod_wsgi-4.5.15

Apache 2.4.18

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You do this by setting the DJANGO_SETTINGS_MODULE environment variable. You can either do this in your Apache vhost configuration, or in the wsgi file itself.

over 4 years ago · Santiago Trujillo Report

0

I solved this by adding DJANGO_SETTINGS_MODULE to my secrets.json file in each environment.

secrets.json:

{
  "FILENAME": "secrets.json",
  "SECRET_KEY": "someSuperSecretiveSecret!",
  "DJANGO_SETTINGS_MODULE": "config.settings.local"
}

wsgi.py:

import json
from django.core.exceptions import ImproperlyConfigured
from pathlib import Path
...

# Directory Paths
BASE_DIR = Path(__file__).resolve().parent

# JSON-based secrets module
SECRETS_JSON = str(BASE_DIR) + '/secrets.json'

with open(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)


DJANGO_SETTINGS_MODULE = get_secret('DJANGO_SETTINGS_MODULE')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", DJANGO_SETTINGS_MODULE)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!