Zope的没落,Django的崛起
django python
1.00
zope python
0.92
一图胜千言,Zope糟糕的文档,不友好的社区注定了它的没落,虽然Zope有很多优秀的地方,但比起Django在很多地方做的太过复杂了。学习Django的过程中有着过去从Zope身上从来没有得到的愉悦,Django为什么会流行? 如果你喜欢这篇文章,欢迎 订阅我的 RSS feed!
django python
1.00
zope python
0.92
一图胜千言,Zope糟糕的文档,不友好的社区注定了它的没落,虽然Zope有很多优秀的地方,但比起Django在很多地方做的太过复杂了。学习Django的过程中有着过去从Zope身上从来没有得到的愉悦,Django为什么会流行? 如果你喜欢这篇文章,欢迎 订阅我的 RSS feed!
说明: 虽然本文是针对django而写,但对于其他python框架应同样适用。 浪点现在只支持mod_python这一种部署方式了,详细了解mod_python请参考mod_python 官方手册翻译
构造虚拟环境:
$ python virtualenv.py –no-site-packages sandbox
virtualenv.py下载地址
浪点默认装了一些有用的Python包,如PIL、lxml等,这些依赖c的包是你无法自己在virtualenv环境中使用的,不过好在直接拷贝过来就可以用了
$ cp /usr/share/pyshared/* -r sandbox/lib/python2.6/site-packages/
切换到虚拟环境,安装自己的包
source sandbox/bin/activate easy_install Django
自定义Pythonhandler:
这里做的最核心的事情就相当于你运行source bin/activate,把Python运行环境切换为你自己的虚拟环境。
#myve.py activate_this = ‘/home/virtualhost/${username}/sandbox/bin/activate_this.py’ execfile(activate_this, dict(__file__=activate_this)) from django.core.handlers.modpython import handler
配置 .htaccess
注意这里的mysite和project。PythonInterpreter可随意写,只要别和其他目录下重复就行了,不写也可以
SetHandler python-program PythonPath "['/home/virtualhost/${username}/sandbox/bin', '/home/virtualhost/${username}/xmu.me/public_html/${mysite}/'] + sys.path" PythonHandler myve SetEnv DJANGO_SETTINGS_MODULE {project}.settings PythonDebug On PythonInterpreter wayhome
现在你就可以访问你的django程序了,have fun :) 如果你喜欢这篇文章,欢迎 订阅我的 RSS feed!
首先,response的所有heaer必须为字符串,unicode,数字都不可以!
当然,在一般的测试服务器中没什么大不了的,但是在apache的mod_wsgi中你或许就会遇到这种很奇怪的问题。
再者,计算response的content-length时需小心。不然就可能出现页面下载不完全的问题。
请注意 len(”中文”) 和 len(u”中文”)的长度是不同的,因此计算输出页面长度之前,最好先encode为utf-8。这样页面显示就正常了。 如果你喜欢这篇文章,欢迎 订阅我的 RSS feed!
Easy_install is not so easy,you may got problem some times. For example,when I install PIL,it will got an error:
Searching for PIL Reading http://pypi.python.org/simple/PIL/ Reading http://www.pythonware.com/products/pil Reading http://effbot.org/zone/pil-changes-115.htm Reading http://effbot.org/downloads/#Imaging No local packages or download links found for PIL error: Could not find suitable distribution for Requirement.parse(’PIL’)
You can got it work like this:
easy_install –find-links http://www.pythonware.com/products/pil/ Imaging
And also,by default,the reportlab 2.3 is not supported [...]
话说python里面的框架还不够多么,这不又来了一个轮子bobo.
这是Jim Fulton(何许人也?Zope的精神领袖是也)最近刚刚写的一个wsgi 框架。和pylons,tubrogears,bfg等新兴wsgi框架同出一辄,都是基于Paste的。 非常小,包含注释在内只有1000多行,40多kb因此速度也很快。
感觉和bfg的设计理念比较类似,但是不同在于bfg明眼人一眼就能看出是对Zope的改造,而bobo就目前看来与zope没有任何关系,除了依赖里有写 zope.testing,但是完全没有用到,可能未来会用于测试。Routes规则,实在和ror太像了!不过其还有独特的SubRoutes。
这个框架目前还没有正式发布,Jim Fulton声称会在下周一发布。 如果你喜欢这篇文章,欢迎 订阅我的 RSS feed!
Technorati Tags: python, django
今天终于拿到了国内的第一本Django中文书《Django web开发指南》。激动之余,也有些小小的失望。
坊间一直流传本书是基于Django 1.0的,不过就书中的例子来看,还是基于旧版本的Django.因此笔者将根据自己的学习进度,将一些变动的地方在这里一一刊出。
第二章 51页
urls.py的修改类似于这样:
# Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns(”, # Example: # (r’^mysite/’, include(’mysite.foo.urls’)), # Uncomment the admin/doc line below and add ‘django.contrib.admindocs’ # to INSTALLED_APPS to enable admin documentation: (r’^admin/doc/’, include(’django.contrib.admindocs.urls’)), # Uncomment the next line to enable the admin: (r’^admin/(.*)’, admin.site.root), )
设置admin应用的时候,可以按书中的方法。也可以创建文件mysite/blog/admin.py,在其中添加:
from mysite.blog.models import BlogPost from django.contrib import admin
admin.site.register(BlogPost)
第二章 57页
mysite/urls.py和mysite/blog/urls.py中都不要括号外面的那个url方法,类似这样:
(r’^blog/’,include(’mysite.blog.urls”)) 如果你喜欢这篇文章,欢迎 [...]