易截截图软件、单文件、免安装、纯绿色、仅160KB

Python Web开发与Apache2+mod_wsgi部署

最近在看Python Web方面的开发,初步接触了Django和web.py(注:和web2py完全不相关)两个框架。
如果结合Apache部署需要一些研究,可能对CGI的不熟悉吧。虽然mod_python也可以,但似乎更流行mod_wsgi 
,我是在Ubuntu安装的,本来想源码编译的,可是make的时候总是报错,最后$sudo apt-get install libapache2-mod-wsgi ,倒也简单。
注:如果采用编译的方式,需要预装apxs2(apxs is the tool for building modules for Apache (apxs2 is for apache2),
$sudo apt-get install apache2-threaded-dev
装好就是修改配置文件了,主要是修改/etc/apache2/sites-available/default文件:
基本照着向导
来就可以,因为是英文的,这里简要介绍如下:
在VirtualHost内添加
   #采用守护模式而非内嵌模式
   WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP}
   WSGIProcessGroup example.com
   #创建python脚本执行的别名,推荐程序脚本放在独立的目录而非DocumentRoot
    WSGIScriptAlias /mywebpy /usr/local/mywebpy/index.py
    <Directory /usr/local/mywebpy>
    Order allow,deny
    Allow from all
    </Directory>
web.py实例代码如下:
#!/usr/bin/env python
import web
urls = (
'/(.*)', 'hello'
)
class hello:
def GET(self, name):
i = web.input(times=1)
if not name: name = 'world'
for c in xrange(int(i.times)): print'Hello,', name+'!'
application = web.application(urls, globals()).wsgifunc()

到这里,还有一个问题,那就是代码中的print语句并不被mod_wsgi支持,你可能会看到internal error之类的信息,通过/var/log/apache2/error.og可以看到详细的信息,那是因为标准输入/输出的语句在WSGI中是不允许的,原因如下:
Q: Why do I get the error 'IOError: sys.stdout access restricted by mod_wsgi'?
A: A portable WSGI application or application component should not output anything to standard output. This is because some WSGI hosting mechanisms use standard output to communicate with the web server. If a WSGI application outputs anything to standard outpu


相关文档:

zz使用 Python 分离中文与英文的混合字串

使用 Python 分离中文与英文的混合字串
LiYanrui

posted @ 大约 1 年前
in 程序设计
with tags
python

, 614 阅读


这个问题是做 MkIV 预处理程序
时搞定的,就是把一个混合了中英文混合字串分离为英文与中文的子字串,譬如,将 ”我的 English 学的不好
&ld ......

使用pdb调试Python程序

使用pdb调试Python程序
 
本文讨论在没有方便的IDE工具可用的情况下,使用pdb调试python程序
 
源码例子
例如,有模拟税收计算的程序:
 
#!/usr/bin/python
def debug_demo(val):
                if val &l ......

python模块学习 smtplib 邮件发送

在基于互联网的应用中,程序经常需要自动地发送电子邮件。如:一个网站的注册系统会在用户注册时发送一封邮件来确认注册;当用户忘记登陆密码的时候,通过邮件来取回密码。smtplib模块是python中smtp(简单邮件传输协议)的客户端实现。我们可以使用smtplib模块,轻松的发送电子邮件。下面的例子用了不到十行代码来发送电子邮 ......

python 2.4与2.5中字符串与datetime转换的区别

python 2.4中datetime有strftime方法而无strptime方法
而python2.5中这两个方法均有,而我的开发环境正好是python 2.5,而运行环境则是python 2.4
开发环境下调试好的程序,在服务器上就不run。查了一下python的官方文档
,斜体写着:New
in version 2.5.
不兼容的代码如下:
Python语言
:
test_strptime.py
res ......

常用的python模块

from link http://www.tt010.net/cms/show_article/1057.html 发表评论 Post by : BossAdmin @[2009-12-12 17:11:20] views:115 adodb:我们领导推荐的数据库连接组件 bsddb3:BerkeleyDB的连接组件 Cheetah-1.0:我比较喜欢这个版本的cheetah cherrypy:一个WEB framework ctypes:用来调用动态链接库 DBUtils:数 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号