回答編集履歴
1
flask_restplusのサンプルを追加
test
CHANGED
@@ -35,3 +35,43 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
というように、JSON文字列ではなくPythonオブジェクトそのものを返しているようですが。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
---
|
42
|
+
|
43
|
+
あぁ、`flask_restplus`モジュールの仕様かな。どっちにしろ自分は知らないのですが。
|
44
|
+
|
45
|
+
[そちらのQuickStartドキュメント](https://flask-restplus.readthedocs.io/en/stable/quickstart.html)を見ても、同様のサンプルになってますね。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```python
|
50
|
+
|
51
|
+
from flask import Flask
|
52
|
+
|
53
|
+
from flask_restplus import Resource, Api
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
app = Flask(__name__)
|
58
|
+
|
59
|
+
api = Api(app)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
@api.route('/hello')
|
64
|
+
|
65
|
+
class HelloWorld(Resource):
|
66
|
+
|
67
|
+
def get(self):
|
68
|
+
|
69
|
+
return {'hello': 'world'}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
if __name__ == '__main__':
|
74
|
+
|
75
|
+
app.run(debug=True)
|
76
|
+
|
77
|
+
```
|