ディレクトリ構造
は動作するはずの手順です。ディレクトリ構造は、conf.py
のパスが正しく設定されている場合と異なる場合があります。
├── 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
スフィンクス設定
conf.py
autodoc
は、Djangoアプリケーションをブートストラップすることができるようにいくつかの設定が必要です。
# 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⇒ Djangoプロジェクトのディレクトリを追加(1 manage.py
)をPythonパスに追加します。これは2と解決のために必要ですautodoc
di直腸が.rst
ファイルにあります。
2⇒設定モジュールの場所にenv変数を設定します。この例は、バニラのdjango-admin設定に基づいています。より洗練された設定構造を使用している場合(たとえば、dev
、staging
、production
の設定は基本設定から拡張されています)、パスを更新するだけです。 myproj.settings.dev
。が最終的にdjango.setup()
を呼び出す
3⇒はスフィンクスがそのままDjangoのセットアップからドキュメントを生成するために必要とDjangoのアプリケーションレジストリを移入するために必要です。
$ make html
とautodoc
を併用する場合は、すべてここに入力する必要があります。
Ahh ...私の 'conf.py'にこれらの変更を加え、myprojectの外にある私のドキュメントフォルダを移動させました。ありがとう! – thanksd