django-tastypie 和 djangorestframework 有什么区别? [英] What are the differences between django-tastypie and djangorestframework?

查看:23
本文介绍了django-tastypie 和 djangorestframework 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要使用一个而不是另一个来为您的 Django 应用程序公开 API?

http://pypi.python.org/pypi/djangorestframework/

http://pypi.python.org/pypi/django-tastypie

解决方案

作为 django-rest-framework 的作者,我有一个明显的偏见 ;) 但我希望如此客观的观点是这样的:

美味派

  • 正如 Torsten 指出的那样,您不会因为与出色的 django-haystack 相同的人写的东西而出错.从我在他们的邮件列表上看到的内容来看,Daniel Lindsey 等人非常有帮助,而 Tastypie 稳定、全面且有据可查
  • 擅长为您提供一组合理的默认行为并使构建具有这种风格的 API 变得异常简单.

Django REST 框架

  • 为您提供 HTML 可浏览的自描述 API.(例如,请参阅教程 API.)能够直接在浏览器中导航和与 API 交互是极大的可用性胜利.
  • 始终试图与 Django 习语保持密切联系 - 建立在 Django 基于类的视图之上,等等......(而 TastyPie 在 Django 的 CBV 存在之前就出现了,所以使用它自己的基于类的视图实现)
  • 我认为底层架构构建得非常好,解耦等等......

无论如何,两者都很好.我可能会将 Tastypie 描述为为您提供一组开箱即用的合理默认值,而 REST 框架则是非常好的解耦和灵活.如果您打算在 API 上投入大量时间,我强烈建议您浏览文档 &每个的代码库,并试图找到更适合您的感觉.

显然,自述文件中还有 'Why TastyPie?' 部分,以及'REST framework 3'.

另请参阅 Daniel Greenfeld 关于为 Django 选择 API 框架的博文,从 2012 年 5 月开始(值得注意的是,距离大型 REST 框架 2.0 发布还有几个月的时间).

Reddit 上的几个帖子也有人在问同样的问题,来自 2013 年 12 月2013 年 7 月..>

Why would you use one over the other, for exposing an API for your Django app?

http://pypi.python.org/pypi/djangorestframework/

http://pypi.python.org/pypi/django-tastypie

解决方案

As the author of django-rest-framework, I've got an obvious bias ;) but my hopefully-fairly-objective opinion on this is something like:

TastyPie

  • As Torsten noted, you're not going to go far wrong with something written by the same peeps as the awesome django-haystack. From what I've seen on their mailing list Daniel Lindsey et al are super-helpful, and Tastypie is stable, comprehensive and well documented
  • Excels in giving you a sensible set of default behaviour and making building an API with that style incredibly easy.

Django REST framework

  • Gives you HTML browse-able self-describing APIs. (EG, see the tutorial API.) Being able to navigate and interact with the API directly in the browser is a big usability win.
  • Tries to stay close to Django idioms throughout - built on top of Django's class based views, etc... (Whereas TastyPie came along before Django's CBVs existed, so uses it's own class-based views implementation)
  • I'd like to think that the underlying architecture is pretty nicely built, decoupled etc...

In any case, both are good. I would probably characterise Tastypie as giving you a sensible set of defaults out of the box, and REST framework as being very nicely decoupled and flexible. If you're planning on investing a lot of time in the API, I'd def recommend browsing through the docs & codebase of each and trying to get a feel for which suits you more.

Obviously, there's also the 'Why TastyPie?' section in it's README, and the 'REST framework 3'.

See also Daniel Greenfeld's blog post on Choosing an API framework for Django, from May 2012 (Worth noting that this was still a few months before the big REST framework 2.0 release).

Also a couple of threads on Reddit with folks asking this same question, from Dec 2013 and July 2013.

这篇关于django-tastypie 和 djangorestframework 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆