question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reading env settings from file using environ leads to crash to some applications like sphinx, django extensions

See original GitHub issue

What 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 run make html

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
uzi0espilcommented, Nov 22, 2019

@Micromegass Glad I was able to help! Cheers.

1reaction
Micromegasscommented, Nov 22, 2019

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!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading env settings from file using environ leads to crash to ...
ImproperlyConfigured: Set the DATABASE_URL environment variable . It seems these applications can't use environ to read from settings from file.
Read more >
Django sphinx documentation does not read environment ...
So it turned out that apparantly some applications can't use environ to read from settings from file. Another problem was that docker alpine ......
Read more >
shell_plus — django-extensions 3.2.1 documentation
synopsis: Django shell with autoloading of the apps database models and ... Command line parameters and settings in the configuration file are merged, ......
Read more >
Django sphinx documentation does not read environment ...
I want to document my cookiecutter django project with sphinx. ... out that apparantly some applications can't use environ to read from settings...
Read more >
Django Compressor Documentation - Read the Docs
See the list of Settings to modify Django Compressor's default behaviour and make adjustments for your website. • In case you use Django's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found