Skip to main content

Improve the Sphinx autodoc for Django classes.

Project description

GitHub Workflow Status PyPi Code coverage Black Code Style GitHub license Documentation Status

logo

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinxcontrib-django-2.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinxcontrib_django-2.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file sphinxcontrib-django-2.0.tar.gz.

File metadata

  • Download URL: sphinxcontrib-django-2.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for sphinxcontrib-django-2.0.tar.gz
Algorithm Hash digest
SHA256 b7e3081d0096386a220dfcb593e5db63b4256f226b79da75c01fbe043504f3a3
MD5 0caa9c18101a3c69ed3531a6d8325184
BLAKE2b-256 f9f3d6d1540244ecb448ddffd5d11b7c0061786539b931e7218bd22378dfa58f

See more details on using hashes here.

File details

Details for the file sphinxcontrib_django-2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinxcontrib_django-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edf70341425247caadc41b14ae4763c79efecd362c0e7db2b5932ccad40e4765
MD5 6c1afdb50cb9a361461fed43af48b9d3
BLAKE2b-256 371dd49cfac54b96b473c51690bb0aef702c95394d4593d52e39b78f822503ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page