大马资讯论坛 - 马来西亚中文资讯平台
标题:
[教学] 如何在ubuntu安装Python?部署一个hello world
[打印本页]
作者:
资讯王
时间:
2015-6-19 23:58
标题:
[教学] 如何在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 )
#return target.geturl()
method = 'GET'
body = ''
2. .py was not found on this server.
我放这个就跑不了if __name__=="__main__":之后我就换成def index(req):
欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://www.freeinfo.com.my/)
Powered by Discuz! X3.3