我有一个烧瓶应用程序,我想使用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:
但是我无法获得app:module(autoflask_sampleapp:app)部分正确。因此,当我运行sphinx-build时,我收到一个错误,即找不到应用程序或模块。
我的应用树看起来像这样:
.
├── admin
├── apis
├── app
│ ├── static
│ └── templates
从应用程序的根目录,我可以说:
from apis import profile
如何在index.rst中配置auto flask以正确查找和加载我的应用程序的API模块?
答案 0 :(得分:3)
我的代码结构,其中带有flask应用程序的application.py文件,我运行我的服务器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文件夹包含源代码。