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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: Django是一种用于构建Web应用程序的Python框架。而Element-UI是一种基于Vue.js的前端UI组件库。要在Django使用Element-UI,你需要在Django项目使用Vue.js,并在前端部分使用Element-UI组件。你可以使用npm或yarn安装Element-UI,然后在Vue组件使用它。 ### 回答2: 在Django使用Element-UI可以通过以下步骤进行: 1. 在Django项目的静态文件目录创建一个新的文件夹,例如"element-ui",用于存储Element-UI的静态文件。 2. 在Element-UI的官方网站上下载最新版本的压缩文件,并将其解压。 3. 将解压后的Element-UI文件的"dist"文件的所有文件复制到步骤1创建的"element-ui"文件。这些文件包括CSS文件和JS文件。 4. 在Django的模版文件,添加Element-UI的CSS和JS文件的链接。例如,可以使用以下代码添加一个CSS链接: ```html <link rel="stylesheet" href="{% static 'element-ui/theme-chalk/index.css' %}"&gt; ``` 5. 在Django的模版文件使用Element-UI的组件。你可以根据需要选择合适的组件,例如按钮、表格、表单等。例如,可以使用以下代码添加一个按钮: ```html <el-button type="primary"&gt;按钮</el-button&gt; ``` 6. 在Django的视图函数,处理Element-UI组件的相关逻辑。根据需要,可以使用Element-UI提供的API和事件来进行交互。 以上就是在Django使用Element-UI的基本步骤。通过这些步骤,你可以在Django项目集成Element-UI,并使用其丰富的组件和样式来开发漂亮和功能丰富的用户界面。 ### 回答3: 在Django使用Element-UI可以提供更好的用户界面和交互体验。Element-UI 是一个基于 Vue.js 的桌面端组件库,具有丰富的 UI 组件和样式。要在 Django 使用 Element-UI,需要按照以下步骤进行设置。 首先,需要将 Element-UI 的样式和脚本导入到 Django 的模板文件。可以通过在模板的 <head&gt; 标签引入 Element-UI 的 CSS 样式文件和 JavaScript 脚本文件来完成。可以从 Element-UI 官方网站下载文件并将其保存在 Django 项目的静态文件目录。 其次,在 Django 的视图函数使用 Element-UI 的组件来构建用户界面。可以根据具体需求,在 Django 的模板文件使用 Element-UI 的组件,例如表单、按钮、弹窗等,来实现不同的交互功能。 另外,在 Django 的视图函数,可以通过 AJAX 请求与后台交互,实现数据的增、删、改、查等操作。Element-UI 提供了丰富的 AJAX 组件和工具,可以方便地与 Django 的后台进行数据交互。 最后,可以根据具体需求进行样式的调整和个性化定制。Element-UI 提供了多个主题和自定义样式的选项,可以根据自己的需求进行界面的美化和样式的调整。 综上所述,通过在 Django 使用 Element-UI,可以提升用户界面和交互体验,实现丰富的功能和样式。但需要注意的是,在使用 Element-UI 时要考虑和 Django 的框架结合,以兼容和保持项目的整体风格和一致性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值