Verzeichnisstruktur
auf einem Vanille mit der folgenden Verzeichnisstruktur hier installieren Gründend sind die Schritte, die funktionieren sollte. Die Verzeichnisstruktur kann unterschiedlich sein, solange der Pfad in conf.py
richtig eingestellt ist.
├── docs
│ ├── Makefile
│ ├── build
│ └── source
│ ├── _static
│ ├── _templates
│ ├── conf.py
│ └── index.rst
└── myproj
├── anapp
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
└── myproj
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
Sphinx Konfiguration
conf.py
braucht ein paar Einstellungen, so dass autodoc
Lage ist, die Django App Bootstrap:
# 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.join(os.path.abspath('.'), '../../myproj')) # <•• 1
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings' # <•• 2
import django
django.setup() # <•• 3
1 ⇒ das Django-Projektverzeichnis angehängt (die mit manage.py
) in den Python-Pfad, der für 2 und für die Auflösung autodoc
di notwendig ist Rectives in den .rst
Dateien.
2 ⇒ Einstellung einer env-Variablen mit der Position des Einstellungsmoduls. Dieses Beispiel basiert auf einem vanilla django-admin setup. Wenn Sie eine komplexere Einstellungsstruktur verwenden (z. B. dev
, staging
, production
Einstellungen, die sich von einigen Basiseinstellungen erstrecken), aktualisieren Sie einfach den Pfad, z. myproj.settings.dev
.
3 ⇒ schließlich django.setup()
Aufruf ist notwendig, Djangos Anwendungsregistrierung zu füllen, die Sphinx, um die Dokumentation von einer intakten Django Setup generieren muss.
Alles sollte jetzt für $ make html
sein, um mit autodoc
zu arbeiten.
Ahh ... habe diese Änderungen an meinem 'conf.py' vorgenommen und meinen docs-Ordner außerhalb meines Projekts verschoben und jetzt funktioniert es! Vielen Dank! – thanksd