Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda