django中使用json-->MochiKit-->simplejson-->setuptools-->egg文件

今天在学习django中,想看看ajax在django中的效果,于是用到了json来进行数据的交换,呵呵,没想到趁这个机会让我接触到了很多PY相关的东西...

 首先我用了一个JS库来实现我的客户端的JS代码..代码,他就是MochiKit,呵呵,初次接触还不太清楚他的利弊,但至少在我的简单AJAX实现中,它很好的帮我解决了问题..

---------

function callJson(){
    var d = loadJSONDoc('/ajax/json/');
    d.addCallbacks(onSuccessJson, onFail);
}

------------

这里用到了这个函数..

-----------

loadJSONDoc(url[, queryArguments...]):

   Do a simple XMLHttpRequest to a URL and get the response as a JSON

-------------

他在MochiKit.Async包中,感兴趣可以直接去官网了解更多的信息..

 

当然光在客户端来接收处理JSON数据明显是不够的,下面就需要在views.py中用相应的模块来返回一个json数据格式,怎么做的呢..答案是:simplejson

 

这是一个第三方的模块,当然这就需要我们去把他安装到我们的服务器上,怎么装,用什么装呢...setuptools帮我们很好的解决了,下载安装后我们就可以十分方便的在命令行里安装我们所需要的模块了..用easy_install命令..

 

呵呵,是不是有点迷糊呢?其实在你安装完setuptools后,在%pythonhome%Scripts下面就存在了easy_install.EXE文件了,你要做的就是把他放到你的环境变量里就OK了

 

 

好了,那下面就需要我们去下载simplejson的安装文件了...

下面你会在你下载的文件里发现一个后缀是.egg的文件..怎么做..在命令行里执行easy_install . 记得要在你的当前目录下执行,或者直接用下面的命令easy_install /my_downloads/OtherPackage-3.2.1-py2.3.egg

 

哦?终于看到了这个陌生的东西*.egg文件...印象中很陌生,查了下资料:这种类型的文件是什么呢?

 

--其实他就是相当于java中的jar文件,他提供了一种在一个PY工程中绑定信息的功能和途径

Python eggs are a way of bundling additional information with a Python project, that allows the project's dependencies to be checked and satisfied at runtime, as well as allowing projects to provide plugins for other projects. There are several binary formats that embody eggs, but the most common is '.egg' zipfile format, because it's a convenient one for distributing projects. All of the formats support including package-specific data, project-wide metadata, C extensions, and Python code.The easiest way to install and use Python eggs is to use the "Easy Install" Python package manager, which will find, download, build, and install eggs for you; all you do is tell it the name (and optionally, version) of the Python project(s) you want to use.Python eggs can be used with Python 2.3 and up, and can be built using the setuptools package (see the Python Subversion sandbox for source code, or the EasyInstall page for current installation instructions).

The primary benefits of Python Eggs are:

  They enable tools like the "Easy Install" Python package manager

  .egg files are a "zero installation" format for a Python package; no build or install step is required, just put them on PYTHONPATH or sys.path and use them (may require the runtime installed if C extensions or data files are used)

  They can include package metadata, such as the other eggs they depend on

   They allow "namespace packages" (packages that just contain other packages) to be split into separate distributions (e.g. zope.*, twisted.*, peak.* packages can be distributed as separate eggs, unlike normal packages which must always be placed under the same parent directory. This allows what are now huge monolithic packages to be distributed as separate components.)

   They allow applications or libraries to specify the needed version of a library, so that you can e.g. require("Twisted-Internet>=2.0") before doing an import twisted.internet.

   They're a great format for distributing extensions or plugins to extensible applications and frameworks (such as Trac, which uses eggs for plugins as of 0.9b1), because the egg runtime provides simple APIs to locate eggs and find their advertised entry points (similar to Eclipse's "extension point" concept).

 

There are also other benefits that may come from having a standardized format, similar to the benefits of Java's "jar" format.

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值