Reading env settings from file using environ leads to crash to some applications like sphinx, django extensions
See original GitHub issueWhat happened?
First of all, I am not sure whether this ticket should be a bug report or an enhancement. Either case, whenever you want to generate docs using sphinx, sphinx should be able run the application. Therefore, for any django project the docs/conf.py
should contains the following additional code:
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../'))
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", path_to_settings)
django.setup()
Using Cookiecutter template, the variable path_to_settings
should be "config.settings.local"
. However, by running make html
this will generate error because function env()
won’t be able to work and will raise the following error:
django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable
To fix, you can replace every instance of env(..)
to the correct value for example:
CELERY_BROKER_URL = env('CELERY_BROKER_URL')
should be replaced with CELERY_BROKER_URL = "redis://redis:6379/0"
Therefore, I have created a new settings script just for documentation and it only contains the minimal settings to make django application run. I called the settings settings_docs.py
and within \docs\conf.py
, the
django settings module will be os.environ.setdefault("DJANGO_SETTINGS_MODULE", config.settings.settings_docs)
Steps to reproduce
- generate .rst files from your apps.
- within
\doc\
directory runmake html
Issue Analytics
- State:
- Created 5 years ago
- Comments:14
Top GitHub Comments
@Micromegass Glad I was able to help! Cheers.
Mate, I it worked. ssh’d into docker and turns out make wasn’t installed. I added
apk add make
to my dockerfile, ran the command again and it worked. Thanks a bunch!!