Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build sphinx documentation for django project

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.

  • Sphinx conf.py file: http://pastebin.com/HTYdc1rR
  • Sphinx index file: http://pastebin.com/bu1r38TQ
  • Result of make html: http://pastebin.com/MWJj94EE
like image 558
miki725 Avatar asked Oct 11 '11 23:10

miki725


People also ask

How do you document your Django project using the Sphinx tool?

Create a documentation directory. Once you've installed Sphinx, you will need to create the document root folder. This folder will hold your documentation and other files you will need (images, about pages, and so on…). Create your document root folder in your project main folder and name it /docs.

What is Sphinx Django?

Sphinx is a popular tool for documenting Python projects, including the ability to generate automatic documentation using docstrings in your source code.


2 Answers

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()
like image 189
Simon Avatar answered Sep 19 '22 15:09

Simon


Add the following to your conf.py and you will not need to set DJANGO_SETTINGS_MODULE each time:

import sys, os

sys.path.append('/path/to/your/project') # The directory that contains settings.py

# Set up the Django settings/environment
from django.core.management import setup_environ
from myproject import settings

setup_environ(settings)
like image 25
Mike Ryan Avatar answered Sep 20 '22 15:09

Mike Ryan