繁体   English   中英

如何配置Sphinx自动烧瓶来记录烧瓶安息API?

[英]How to configure Sphinx auto flask to document flask-restful API?

我有一个烧瓶应用程序,我想使用Sphinx的autoflask指令来记录烧瓶 - 宁静的API。

https://pythonhosted.org/sphinxcontrib-httpdomain/#module-sphinxcontrib.autohttp.flask

我已经通过pip安装了模块并运行了sphinx-quickstart,这给了我一个conf.py和index.rst。

我已经尝试将扩展名放入conf.py:

extensions = ['sphinxcontrib.autohttp.flask']

并根据文档将指令转换为index.rst:

.. autoflask:: autoflask_sampleapp:app
:undos-static:

但我无法得到应用程序:模块(autoflask_sampleapp:app)部分正确。 因此,当我运行sphinx-build时,我收到一个错误,即找不到应用程序或模块。

我的app树看起来像这样:

.
├── admin
├── apis
├── app
│   ├── static
│   └── templates

从应用程序的根目录,我可以说:

from apis import profile

如何在index.rst中配置auto flask以正确查找和加载我的应用程序的API模块?

我的代码结构,其中application.py文件与flask app,我运行我的服务器python appllication.py runserver

├── application.py
├── _build
│   ├── doctrees
│   │   ├── environment.pickle
│   │   └── index.doctree
│   └── html
│       ├── genindex.html
│       ├── http-routingtable.html
│       ├── index.html
│       ├── objects.inv
│       ├── search.html
│       ├── searchindex.js
│       ├── _sources
│       │   └── index.txt
│       └── _static
├── conf.py
├── index.rst

在conf.py中,您应该包含扩展名,并在您的项目中包含您的application.py或任何其他主要烧瓶app文件的abs路径。

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

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinxcontrib.autohttp.flask',
    'sphinxcontrib.autohttp.flaskqref'
]

您可以使用蓝图,烧瓶应用程序中的视图

My documentation!
=======================================


.. qrefflask:: application:application
   :undoc-static:

=======================================
Api details!
=======================================

.. autoflask:: application:application
   :undoc-static:

换句话说,在运行make html之前,你应该通过python sys path sys.path.insert(0,os.path.abspath('/ home / myproject /'))在你的根应用程序文件夹中添加abs路径,其中/ home / myproject文件夹包含您的源代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM