2016-11-22 4 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

よう

に見えるが、右にそれが可能です1つはGET用、もう1つはPOST用ですか? IDは実際には、すべての関数を2つの別々のget/post関数に分割することを避けるのが好きです。

person_id GET要求の変数のように、自動フラッシュ出力必須引数をrequest.argsまたはrequest.formに渡すことは可能ですか?

+0

これを実行しましたか? – jfunk

+0

私はプロジェクトから遠ざかっていませんでした:/私は新しいプロジェクトから少し時間を取ってすぐにそれを振り返ります。入力ありがとう – Busturdust

答えて

0

Flaskのautodocからオーバーロードされたビュー機能を削除し、リクエストを個別に定義し、残りのAPIは自動的に生成されるようにしてください。

ここでは一例です... conf.py

(プラグインの順序が重要です):reStructuredTextのファイルで

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

:あなたに関して

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. 

2番目の質問は、のディレクティブを参照してください0 here

関連する問題