【问题标题】:Sphinx automodule: failed to import moduleSphinx 自动模块:导入模块失败
【发布时间】:2019-06-19 11:34:15
【问题描述】:

我正在学习 Sphinx 来记录我的 Django 项目。

我的项目结构是这样的

app
|- docs
   |- build
   |- source
      |- conf.py
      |- index.rst
   |- make.bat
   |- Makefile
|- src
   |- authentication
      |- __init__.py
      |- models.py
      |- ...
   |- myapp
      |- __init__.py
      |- settings.py
      |- wsgi.py
   |- manage.py

在`app/docs/source/conf.py中,查找doc的路径设置为

import os
import sys
sys.path.insert(0, os.path.abspath('../../src'))

并且index.rst有内容

App's documentation!
=============================================

.. automodule:: manage
   :members:

.. toctree::
   :maxdepth: 2
   :caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

在运行中

make html

它会生成包含默认内容且没有来自 Django 应用程序的内容的空白文档页面。

我创建了许多应用程序,每个应用程序都包含许多文件。我想从整个 Django 应用程序的文档字符串中自动生成文档。

【问题讨论】:

    标签: django python-sphinx django-sphinx


    【解决方案1】:

    看看这个https://medium.com/@sschannak/sphinx-for-django-documentation-2b9c900c6cfa。看起来您缺少 django 设置,您需要为要记录的项目模块添加 .. automodule::。

    【讨论】:

    • 谢谢。但是我可以自动记录INSTALLED_APPS 列表中包含的应用程序的所有文件吗?文件很多,很难单独添加所有视图、模型等。
    猜你喜欢
    • 2012-05-06
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 2016-12-29
    • 2013-12-03
    相关资源
    最近更新 更多