资讯王 发表于 2015-6-19 23:58:42

[教学] 如何在ubuntu安装Python?部署一个hello world

[教学] 如何在ubuntu安装Python?部署一个hello world

前提,你已经安装好了apache2

1. 安装libapache2-mod-python
sudo apt-get install libapache2-mod-python

2. 部署你的Directives
AddHandler mod_python py
PythonHandler mod_python.publisher
PythonDebug On
DocumentRoot /var/www/domain.my
ServerName domain.my
ServerAlias www.domain.my
<Directory "/var/www/domain.my">
#allow from all
#Options +ExecCGI
AddHandler mod_python py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>


3. Create一个file,命名test.py
def index(req):
return "Hello World";

4. www.domain.my/test.py 就成功啦,超简单的。


而外的httplib2 lib,如果你有需要
1. sudo apt-get install python3-httplib2
2. sudo apt-get install python-pip
3. sudo apt-get install python-pip3
4. pip2 install httplib2 --upgrade
5. pip3 install httplib2 --upgrade

常见问题
1. ^ IndentationError: unexpected indent
前面的空位少或多一个都不行,要一致的
def index(req):
        #Build query string & specify type of API call
        target = urlparse(uri + path )
        #returntarget.geturl()
        method = 'GET'
        body = ''

2. .py was not found on this server.
我放这个就跑不了if __name__=="__main__":之后我就换成def index(req):

页: [1]
查看完整版本: [教学] 如何在ubuntu安装Python?部署一个hello world