2016-11-22 19 views
1

我有一個Flask應用程序,我正在爲通過python-sphinx構建文檔。Sphinx Autoflask - 區分相同功能的GET和POST請求的文檔字符串

我目前使用從sphinxcontrib.autohttp.flask

的autoflask擴展我的問題是:我如何可以準備一個文檔字符串,其正確適用不同的信息相同路線的GET版本和POST版本。

例如一個小功能:

@app.route('/add_event', methods=['GET', 'POST']) 
def add_event(): 
    """ 
    ..http:get:: /add_event 
     :return: Test 
    ..http:post:: /add_event 
     :return: Test2 
    """ 
    if request.method == 'GET': 
     # get some things 
     person_id = request.args.get('id') 
     return render_template('create_event.html', race_event_form=test_form) 
    if request.method == 'POST': 
     # post some things 

     return redirect('/person_profile/id/{0}'.format(request.args.get('id'))) 

我在conf.py電流擴展

extensions = [ 
    'sphinx.ext.autodoc', 
    'sphinx.ext.ifconfig', 
    'sphinx.ext.viewcode', 
    'sphinx.ext.githubpages', 
    'sphinxcontrib.httpdomain', 
    'sphinxcontrib.autohttp.flask', 
    'sphinxcontrib.autohttp.flaskqref' 
] 

獅身人面像輸出看起來像

enter image description here

是否有可能向右一個GET和另一個POST的一件事?我真的很想避免將每個函數分成兩個單獨的get/post函數。

另外,是否有可能在GET請求中自動輸入通過或request.form所需的自變量,如person_id變量?

+0

你有沒有解決這個問題? – jfunk

+0

我沒有,離開這個項目:/我很快回頭看看它,當我從新項目中抽出一些時間。感謝您的輸入 – Busturdust

回答

0

嘗試從Flask autodoc中刪除重載的視圖函數,並單獨定義請求,同時將剩餘的API自動生成。

下面是一個例子...

conf.py(插件的順序是重要):

extensions = [ 
    'sphinx.ext.autodoc', 
    'sphinxcontrib.httpdomain', 
    'sphinxcontrib.autohttp.flask', 
] 

在reStructuredText的文件:

API 
=== 

.. autoflask:: path.to.your:app 
    :undoc-static: 
    :undoc-endpoints: your_view_method 

.. http:get::/your_view_endpoint 

    Some docstring you wrote. 

.. http:post::/your_view_endpoint 

    Another docstring you wrote. 

至於你第二個問題,你可以看看的指令0 here