Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Django settings for sphinx (documentation)

I have a Django app I'm trying to set up documentation for. The directory structure is as follows:

- doc
- project
| - manage.py

I have set up the paths so that Sphinx can see things, but when I try to use autodoc, some of the settings I've set in settings.py aren't available. Here's how I'm setting up the environment, what am I doing wrong?

from django.core.management import setup_environ
from project import settings

setup_environ(settings, 'project.settings')
like image 405
Brian Hicks Avatar asked Mar 23 '12 20:03

Brian Hicks


People also ask

Does Sphinx support markdown?

To support Markdown-based documentation, Sphinx can use MyST-Parser. MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.


1 Answers

I can only think of two causes of why the setup_environ() call in your Sphinx's conf.py does not work:

  • It does not do its magic early enough. You import other things that already need the settings before that line.

  • The settings.py itself is importing too much. Would be weird if this is the case, though.

Note that setup_environ() is deprecated. It won't be removed till Django 1.6, though.

Another option is to use os.environ right at the top of your conf.py script. You're guaranteed to be in time there :-)

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
like image 134
Reinout van Rees Avatar answered Oct 14 '22 23:10

Reinout van Rees