Python
共 17 篇文章
使用python快速共享文件
一般来说类linux系统之间的文件共享通常使用nfs,而linux 和Windows文件共享则使用samba,这两个服务器功能强大,但是使用起来免不了要配置一番 如果你的机器上装了python可以使用python自带的http服务器 进入你要共享文件的目录执行, ptyhon -m SimpleHTTPServer 对方只要在浏览器里输入你的IP地方加8000端口(例如192.168.1.104:8000)就可以看到共享目录下文件。
2009-09-17 03:55 · Python
新版本代替form_for_model
1.0之前的newforms.form_for_model()和 newforms.form_for_instance()在1.0的forms里面都没有了 可以用forms.models.modelform_factory()
2009-08-11 23:03 · Python
django自定义tag传入参数
#coding=utf-8 from django import template register = template.Library() class ZNode(template.Node): def __init__(self,mas): self.ma=ma pass def render(self, context): return self.ma def do_z(parser, token): tag_name, arg = token.contents.split(None, 1) return ZNode(arg) register.tag('z', do_z)
2009-08-05 15:48 · Python
样例代码学习
#!/usr/bin/env python #pyaria2.py import os, sys, urllib def usage(): print """Usage: python tharia2.py [OPTIONS] URL OPTIONS: As same as options of aria2c""" def get_url_list(url, listpath): if not os.path.exists(listpath): print "Getting URL list, please wait..." f = urllib.urlopen("http://cocobe…
2009-07-05 07:08 · Python
Python之urllib使用
>>> import urllib >>> url = r"http://www.ssylgc.com/images/index1.swf" >>> path = r"c:/index1.swf" >>> data = urllib.urlretrieve(url, path) >>>
2009-06-18 08:10 · Python
Django标签之divisibleby
Example: {% if value|divisibleby:"2" %} Even! {% else %} Odd! {% else %} Returns True if the value is divisible by the argument.
2008-12-11 11:48 · Python
Django标签之regroup
regroup 把一列相似的对象根据某一个共有的属性重新分组。 要解释清这个复杂的标签,最好来举个例子。比如, people 是包含 Person 对象的一个列表, 这个对象拥有 first_name 、 last_name 和 gender 属性,你想这样显示这个列表: * Male: * George Bush * Bill Clinton * Female: * Margaret Thatcher * Condoleezza Rice * Unknown: * Pat Smith 下面这段模板代码就可以完成这个看起来很复杂的任务: {% regroup people by gender…
2008-12-11 11:41 · Python
DJANGO Fastcgi配置
The FastCGIExternalServer directive tells Apache how to find your FastCGI server. As the FastCGIExternalServer docs explain, you can specify either a socket or a host . Here are examples of both: # Connect to FastCGI via a socket / named pipe. FastCGIExternalServer /home/user/public_html/mysite.fcg…
2008-12-01 16:28 · Python
Python function decorators
首先定义你自己的方法或者函数。如: def f(): pass 然后定义修饰函数或者方法 def H(func): print 'do H' return func 那么如果你给f加上了修饰H那就等于 f = H(f) 合起来的代码是: def H(func): print 'do H' return func @H def f(): pass 修饰函数或者方法还可以带参数,同时也可以在真正的函数调用前或者后利用修饰函数作一些事,这里就不详说了。看代码: def A(arg): print 'A arg = ', arg #传了参数给修饰函数 def _A(func): def new_fu…
2008-11-04 17:34 · Python
django摘要
1、^ 表示匹配字符串的最开始, $ 则是匹配字符串的最末 2、settings.py 包含了所有的相关配置,其中一个最重要的配置就是 ROOT_URLCONF ROOT_URLCONF 告诉Django哪个Python模块应该用作 URLconf。 3、当服务器收到一个HTTP请求以后,一个服务器特定的 handler 会创建 HttpRequest 并传递给下一个组件并处理。 这个 handler 然后调用所有可用的Request或者View中间件。这些类型的中间件通常是用来增强 HttpRequest 对象来对一些特别类型的requets做些特别处理。只要其中有一个返回 HttpRes…
2008-10-13 23:31 · Python
PyAmf配置
http://blog.eshangrao.com/2008/02/16/447/ 搭建Flex和Django的桥梁:PyAmf的安装 以上我们已经准备好了后台环境,创建了初始的数据,那么我们的Flex程序如何与Django交互呢,答案是PyAmf,这个是Python的Amf实现,通过他,Flex就可以使用Amf的方式和Python程序交互。值得一提的是,这个支持Amf3。 PyAmf目前的稳定版本是0.1,和前面安装Django一样的考虑,我们也安装svn的开发版本 cd $work_root/server svn co http://svn.pyamf.org/pyamf/trunk p…
2008-09-17 10:53 · Python
使用pyAmf连接python和flex
Exposing functions for AMF remoting is simple by defining a gateway (a dispatcher) like this # yourproject/yourapp/amfgateway.py from pyamf.remoting.gateway.django import DjangoGateway def echo(data): return data services = { 'myservice.echo': echo # could include other functions as well } echoGate…
2008-09-17 10:25 · Python
【DJANGO学习】基本知识点
init .py: An empty file that tells Python that this directory should be considered a Python package. manage.py: A command-line utility that lets you interact with this Django project in various ways settings.py: Settings/configuration for this Django project. Django settings will tell you all about…
2008-09-16 23:18 · Python
asyncore.py
asyncore库是python的一个标准库,它是一个异步socket的包装。我们操作网络的时候可以直接使用socket等底层的库,但是asyncore使得我们可以更加方便的操作网络,避免直接使用socket,select,poll等工具时需要面对的复杂。 这个库很简单,包含了一个函数和一个类 * loop()函数 * dispatcher基类 需要注意的是,loop函数是全局的,不是dispatcher的方法 每一个从dispatcher继承的类的对象,都可以看作我们需要处理的一个socket,可以是TCP连接或者UDP,甚至是其它不常用的。使用容易,我们需要定义一个类,它继承dispat…
2008-04-09 10:59 · Python
【Python学习】python哲学
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts.
2008-03-29 23:05 · Python