How to build sphinx documentation for django project

miki725 picture miki725 · Oct 12, 2011 · Viewed 11.3k times · Source

I have a django project, which I document using reST in docstrings to do the following:

  1. Help diagloags within IDE
  2. Later on to build HTML documentation using Sphinx

My documentation shows up properly within IDE (PyCharm), however I can't configure Sphinx to generate HTML documentation for me.

Here is the structure of my project

+--------------------------------------------+
|  /saassapp         # django project path   |
|     /docs          # dir for sphinx        |
|        conf.py     # sphinx config file    |
|        ...                                 |
|     settings.py    # django settings       |
|     /studyview     # django app            |
|        ...
|     ...                                    |
+--------------------------------------------+

Any ideas? An examle of the conf.py file would be very useful. Thank you.

EDIT

My project name is saassapp and the module I am trying to make a doc for is called studyview.

Answer

Simon picture Simon · Nov 17, 2015

The migration features introduced in Django 1.7 prevents the previous answers from working on newer versions. Instead you will have to do a manual setup. Analogous to all previous answers you'll first have to make sure Django can find your settings, and then call django.setup() which will load the settings and setup your models. Add this to your Sphinx project's conf.py:

os.environ['DJANGO_SETTINGS_MODULE'] = 'projectname.settings'
import django
django.setup()