3

私が書いた単純な請求書アプリから Web サービスを作成したいと思います。Apache fop から json とできれば pdf ファイルを返すようにしたいと思います。HTML Web ページは必要ありません。Python デスクトップ アプリケーションからサービスにアクセスします。

ドキュメントのテンプレート セクションを無視できますか?

私が抱えている最も問題は、関数に複数のパラメーターを受け入れることです。

以下のサンプル コードを複数の入力を受け入れるようにするにはどうすればよいですか?

@app.route('/post/<int:post_id>')
def show_post(post_id):
    # show the post with the given id, the id is an integer
    return 'Post %d' % post_id

私はプログラミングに不慣れで、Web サービスについてはなおさらです。これについて間違った方法で行っている場合は、お知らせください。

4

3 に答える 3

4

html セクションは無視してかまいません。Flask は、Web アプリを作成するための優れた軽量な方法です。必要に応じて、すべての URL への応答として json (またはその他のデータ) を返すことができ、html テンプレートを完全に無視できます。

ルート定義に必要な数のパラメーター/正規表現を含めることができます。それぞれが関数の新しいパラメーターを作成します。

@app.route('/post/<int:post_id>/<int:user_id>/')
def show_post(post_id, user_id):
    # show the post with the given id, the id is an integer
    return 'Post %d' % post_id

Flask は URL ルーティングで正規表現をサポートしていますか?

于 2012-09-10T16:31:32.173 に答える
2

フラスコは仕事に適したツールですか?

Flask は、Bottle または webpy としてのマイクロ python Web フレームワークです。私の考えでは、ミニマリストの Web フレームワークはあなたの仕事に適しています。

URL の変数部分である「変数ルール」と、関数の「従来の」引数を混同しないでください。

from flask import Flask
app = Flask(__name__)

@app.route('/post/<int:post_id>', defaults={'action': 1})
def show_post(post_id, action):
    # show the post with the given id, the id is an integer
    # show the defauls argument: action.
    response = 'Post %d\nyour argument: %s' % (post_id, action)
    return response

if __name__ == '__main__':
    app.run()
于 2012-09-10T16:46:24.083 に答える