Sphinx Docs Not Importing Django Project Settings
I just recently move a Django project into a new virtualenv. The project works fine, but I am having trouble building my Sphinx Documentation. in my conf.py I have this: import sy
Solution 1:
Turns out the conf.py needs to look like this:
import sys, os
sys.path.append('/path/to')
from myproject import settings
from django.core.managementimport setup_environ
setup_environ(settings)
Hope this might help someone.
Solution 2:
Django 1.4 deprecated setup_environ
. Here's similar code for Django 1.4 and later:
import sys, os
cwd = os.getcwd()
parent = os.path.dirname(cwd)
sys.path.append(parent)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
Solution 3:
Having this problem with a Django 1.7.5 project and I think it's down to some strange project layout decisions we made, but I needed one extra step to solve this using jwhitlock's answer:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
from django.confimport settings
When I did that useless import it found my custom Django settings which were specified in DJANGO_SETTINGS_MODULE
but were not found by the autodoc process. I think this is because the project lives in a folder whose parent has the same name, but inspecting sys.path
only shows the "right" folder so the import should work but blows up saying it can't find my settings.
Post a Comment for "Sphinx Docs Not Importing Django Project Settings"