简体   繁体   English

Flask MethodView与Flask-Restful资源

[英]Flask MethodView vs Flask-Restful Resource

What is difference between MethodView and Resource? MethodView和Resource之间有什么区别?

It implements API by flask-restful: 它通过flask-restful实现API:

class API(Resource):
    decorators = [...,]

    def get(self):
        # do something
    def post(self):
        # do something
    def put(self):
        # do something
    def delete(self):
        # do something

Actually, it can be replaced by flask: 实际上,可以用flask代替它:

class API(MethodView):
    decorators = [...,]

    def get(self):
        # do something
    def post(self):
        # do something
    def put(self):
        # do something
    def delete(self):
        # do something

I think Flask has offered enough about establishing Restful API. 我认为Flask对建立Restful API提供了足够的支持。 I can't find flask-restful can do more something than flask because they have CRUD methods and decoraters in class of mechanism in the same. 我发现烧瓶不止于烧瓶可以做更多的事情,因为它们在同一类机制中具有CRUD方法和装饰器。 What is special about flask-restful? 烧瓶安宁有什么特别之处?

I am evaluating whether or not Flask-Restful is really necessary for me. 我正在评估是否需要Flask-Restful。 Please tell me, thanks. 请告诉我,谢谢。

I was wondering same thing and according to this post Resource is inherited from Methodview ( http://blog.miguelgrinberg.com/post/designing-a-restful-api-using-flask-restful ). 我在想同样的事情,根据这篇文章,资源是从Methodview继承的( http://blog.miguelgrinberg.com/post/designing-a-restful-api-using-flask-restful )。 Article describes also added value to compared to plain Flask like "Flask-RESTful provides a much better way to handle this with the RequestParser class. This class works in a similar way as argparse for command line arguments." 文章还描述了与普通Flask相比的附加值,例如“ Flask-RESTful提供了一种更好的方法来使用RequestParser类来处理此问题。此类的工作方式与argparse相似,适用于命令行参数。” And much of work with your API is still something to do with authentication and security like parameters/data checking. API的大部分工作仍与身份验证和安全性(例如参数/数据检查)有关。

Thx to Miguel to excellent blog. 感谢Miguel撰写出色的博客。 I'm using flask-restful because it seems to be quite mature. 我正在使用烧瓶安宁瓶,因为它似乎已经相当成熟。

If your need is very tiny, then I think you can use flask only approach. 如果您的需求很小,那么我认为您可以使用仅烧瓶的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM