0 0 0 0


I have a flask app that I want to use Sphinx's autoflask directive to document a flask-restful API.

I have installed the module via pip and run sphinx-quickstart, which gives me a and index.rst.

I've tried putting the extension into

extensions = ['sphinxcontrib.autohttp.flask']

and the directive into index.rst as per the documentation:

.. autoflask:: autoflask_sampleapp:app

But I can't get the app:module (autoflask_sampleapp:app) part correct. As a result, when I run sphinx-build I get an error that either the app or the module are not found.

My app trees looks like this:

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

and from the app's root directory, I can say:

from apis import profile

How do I configure auto flask in the index.rst to correctly find and load my app's API modules?

Best Answer:

My code structure, where file with flask app, I run my server python runserver

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

In you should include extensions and include abs path to you or any other main flask app file in your project.

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 = [

After you can use blueprints, views from your flask app

My documentation!
.. qrefflask:: application:application
Api details!
.. autoflask:: application:application

In other words, before run make html, you should add abs path to you root application folder via python sys path sys.path.insert(0, os.path.abspath('/home/myproject/')), where /home/myproject folder with your source code.

Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs