"最佳"办法的Django与Ajax库整合 [英] "Best" way to integrate Django with an Ajax library

查看:102
本文介绍了"最佳"办法的Django与Ajax库整合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,马场,但有什么好的方法可以JavaScript库与一个人的Django应用程序集成?

Obviously, horses for courses, but what are some good ways to integrate javascript libraries with one's Django application?

我打算使用jQuery,主要是因为它似乎是流行的,看起来强大的(但我接受其他的建议)。

I'm planning on using jQuery, mostly because it seems popular and looks powerful (but I'm open to other suggestions).

是否有蟒蛇端库是非常有益的或必要?或者是它最好只是创建JSON观点,与手工code的JavaScript(使用合适的JavaScript框架)?

Are there python-side libraries that are very helpful or essential? Or is it best simply to create JSON views, and hand-code the javascript (using an appropriate javascript framework)?

我在Dajax看着(暂时的),但基于缺乏​​文档,目前还不清楚,这真的让我非常喜欢。我肯定会preFER的东西多一点的文档。

I've looked (briefly) at Dajax, but based on the scant documentation, it's not clear that it really gives me very much. I would certainly prefer something with a bit more documentation.

在这里其他的答案表明,pjax不一定与许多浏览器正常工作,所以这是的。

Other answers here suggest that pjax doesn't necessarily work well with many browsers, so that's out.

编辑:谢谢大家。我将着眼于tastypie简化暴露出一些JSON的看法,人领写一些JavaScript的手(这成就了一点点,今年年初,似乎要好得多比它在90年代末)。

Thanks everyone. I'll be looking at tastypie to simplify exposing some json views, and man up to write some javascript by hand (Which having done a tiny bit earlier this year, seems much better than it was in the late 90s).

推荐答案

在Python的一面,我建议你看的 活塞 和的 tastypie

On python side, I'd suggest to look at piston and tastypie.

(与AJAX + Django的自己开始,我还发现Dajax,但去与活塞 -felt更多的UNIX路对我来说,不喜欢这些所有一体式的解决方案,虽然活塞没有更新了很长一段时间了,所以我建议你 tastypie ,这是积极维护。)

(Starting with AJAX + Django myself, I also found Dajax, but went with piston—felt more ‘unix-way’ for me, don't like these all-in-one solutions. Though piston wasn't updated for a long time now, so I'd recommend tastypie, which is actively maintained.)

编辑。还有一个类似的项目, 的Django的REST框架 。从来没有用它自己的是,它是pretty的新的。

EDIT. There's also a similar project, django-rest-framework. Never used it myself yet, it's pretty new.

基本上,这些库帮你创建你的模型一个全功能的读写API,这样你就可以从通过HTTP您的JavaScript执行创建,读取,更新,删除操作。你不需要定义任何意见或串行。相反,你定义的资源的,这是一个不错的抽象,我想。

Basically, these libs help you create a fully working read-write API for your models, so you can perform create-read-update-delete operations from your javascript via HTTP. You don't need to define any views or serializers. Instead, you define resources, which is a decent abstraction, I think.

和它通常采取code短短的几行,特别是如果你的资源都依赖于模型。

And it usually takes just a few lines of code, especially if your resources are tied to models.

不过,如果你需要更复杂的东西,你可以<打击>重新考虑你的设计写你的意见。基于类的意见,这是pretty的容易了。看看这个片段例如。

However, if you need something more complicated, you can rethink your design write your views. With class-based views, it's pretty easy, too. Take a look at this snippet for example.

这篇关于&QUOT;最佳&QUOT;办法的Django与Ajax库整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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