/ 中存储网

Apache服务器中配置python运行环境的具体命令和步骤分享

2014-04-03 15:16:01 来源:itjs.cn

这几天准备先了解下Python,先把环境配好再说

 

因为我一直接是用php做开发的,所以我用Apache+mod_python+mysql_python 

NameVirtualHost *:8080

<VirtualHost *:8080>

        ServerName www.investigation.com

        ServerAlias investigation

        DocumentRoot "D:/Project/sinotrac/investigation"

        <directory "D:/Project/sinotrac/investigation">

AllowOverride None

                Options Indexes FollowSymLinks

                Order allow,deny

                Allow from all

        </directory>

        <Location "/">

                SetHandler python-program

                PythonPath "['D:/Project/sinotrac'] + sys.path"

                PythonHandler django.core.handlers.modpython

                SetEnv DJANGO_SETTINGS_MODULE investigation.settings

                PythonOption django.root /investigation

                PythonDebug On

        </Location>

        Alias /site_media "D:/Project/sinotrac/investigation/media"

        Alias /media "C:/Python25/Lib/site-packages/django/contrib/admin/media"

        <Directory "C:/Python25/Lib/site-packages/django/contrib/admin/media/">

            Order deny,allow

            Allow from all

        </Directory>

        <Location "/media">

            SetHandler None

        </Location>

        <Location "/site_media">

            SetHandler None

        </Location>

        <Location "/admin_media">

            SetHandler None

        </Location>

#        <LocationMatch ".(jpg|gif|png|css|js)$">

#            SetHandler None

#        </LocationMatch>

</VirtualHost> 

嘿嘿。。我没有用django框架了,所以做了个简单配置

<VirtualHost 192.168.1.47>

    ServerName py.ww.com

    DocumentRoot F:Python

    <Directory "F:Python">

        #AddHandler mod_python .py

        SetHandler mod_python

        PythonHandler mod_python.publisher

        PythonDebug On

        Options FollowSymLinks

        AllowOverride FileInfo

    </Directory>

    <Files ~ ".(gif|html|jpg|png)$">

        SetHandler default-handler

    </Files>

</VirtualHost>

在根目录下新建index.py,内容如下:

#coding:gb2312

def index(req):

    req.write("This is the Index!")

    return

def hello(req):

    req.write("hello!!!")

    return

def get(req,name=""):

    if name:

       req.write("参数:"+name);

    else:

       req.write("no param.");

    return