Improve the Sphinx autodoc for Django classes.
Project description
sphinxcontrib-django2
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:)
This is a fork of sphinxcontrib-django, which seems to be no longer maintained.
Installation
Install the package via pip:
pip install sphinxcontrib-django2
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_django2 to installed extensions
extensions = [
"sphinxcontrib_django2",
]
# 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
Hashes for sphinxcontrib-django2-1.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c60962009fcac99c65b091a188814f4fa9b080042e92f117582cdef9b7ff0e56 |
|
MD5 | a499de0c1b96157278149678246d18fb |
|
BLAKE2b-256 | 546ad84a7bc3ee9815a0c5dc72334f5fbccb7630994ac48a63f6089224e0a42c |
Hashes for sphinxcontrib_django2-1.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5645f304a8140a1176114fb5ebff3649440a8ba1df40c918008ad5c70ade0762 |
|
MD5 | 49deccf001f585832f4c67caa3b7072b |
|
BLAKE2b-256 | e02adbe93c334aa5fc36ca6709854d391d0cf4458a0cd10aff01969143a86d7e |