Improve the Sphinx autodoc for Django classes.
Project description
sphinxcontrib-django
This is a sphinx extension which improves the documentation of Django apps.
Features
Improvements for the output of Sphinx’s autodoc for Django classes:
List all model and form fields as class parameters
Improve model field representations
Link related and reverse related fields to the referenced class
Hide irrelevant runtime information like declared_fieldsets, fieldsets and Meta from classes
Add information about autogenerated methods
Fix intersphinx mappings to Django modules
Custom text roles to cross-reference the documentations of Django (:setting:, :templatetag:, :templatefilter:, :fieldlookup:) and Sphinx (:event:, :confval:)
Installation
Install the package via pip:
pip install sphinxcontrib-django
Configuration
Add the following to your Sphinx config file conf.py:
# Add source directory to sys.path
sys.path.insert(0, os.path.abspath("../src"))
# Add sphinxcontrib_django to installed extensions
extensions = [
"sphinxcontrib_django",
]
# Configure the path to the Django settings module
django_settings = "myapp.settings"
Optionally, you can include the table names of your models in their docstrings with:
# Include the database table names of Django models
django_show_db_tables = True
Advanced Usage
If you want to run custom code which depends on Django, e.g. to monkeypatch your application during documentation build, you might run into an ImproperlyConfigured exception:
Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Therefore, this Sphinx extension emits the event django-configured after django.setup() is finished, so you can run your code the following way in conf.py:
def patch_django(app):
"""
Your custom code here
"""
def setup(app):
app.connect("django-configured", patch_django)
Contributing
Pull requests are always welcome!
You can install all requirements of the development setup with the extras dev, test, doc and optional:
python3 -m venv .venv
source .venv/bin/activate
pip install -e .[dev,test,doc,optional]
pre-commit install
Run the tests and generate the coverage report with:
coverage run
coverage html
Build the documentation with:
cd docs
make html
The documentation is automatically deployed to Read the Docs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sphinxcontrib-django-2.3.tar.gz
.
File metadata
- Download URL: sphinxcontrib-django-2.3.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57734906e188949b05c6c4d020bbae7f82bdec27a0e9540cbe33fcf638d8c75e |
|
MD5 | a6be2008fc27c34caad7d222ba8accbd |
|
BLAKE2b-256 | de3022a4b466c6460279d7d578f3447b6c079f5b1a619a9a6b85089a1b4a3b89 |
File details
Details for the file sphinxcontrib_django-2.3-py3-none-any.whl
.
File metadata
- Download URL: sphinxcontrib_django-2.3-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e98a8f2414dbcaa2d996603e3ff9b9f52bc345e8321dc2336c6a8140e8296003 |
|
MD5 | 7148a3799c7a5ffd9470cd7ca6805c46 |
|
BLAKE2b-256 | e2127d4589926bee752db9340c5c078e520064468bf4e3cb27012884da43f6ed |