Python & XAMPP on Windows: how to?

前端 未结 2 695
太阳男子
太阳男子 2020-12-23 18:36

I have installed on my Win7x64 Xampp and Python 2.7.

Now I\'m trying to get the \"power\" of Python language... how can I do it?

I\'ve tried with mod_python

2条回答
  •  生来不讨喜
    2020-12-23 19:00

    Yes you are right, mod_python won't work with Python 2.7. So mod_wsgi is the best option for you.

    I would recommend AMPPS as python environment is by default enabled with mod_python and python 2.5. AMPPS Website

    if you still want to continue,

    Add this line in httpd.conf

    LoadModule wsgi_module modules/mod_wsgi.so
    

    Uncomment the line in httpd.conf

    Include conf/extra/httpd-vhosts.conf
    

    Open vhost file httpd-vhosts.conf and add

    NameVirtualHost 127.0.0.1:80
    
        
            Options FollowSymLinks Indexes
            AllowOverride All
            Order deny,allow
            allow from All
        
        ServerName 127.0.0.1
        ServerAlias 127.0.0.1
        WSGIScriptAlias /wsgi "path/to/wsgi_test.wsgi"
        DocumentRoot "path/to/htdocs"
        ErrorLog "path/to/log.err"
        CustomLog "path/to/log.log" combined
    
    

    Add the following lines in wsgi_test.wsgi

    def application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'
    
        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)
    
        return [output]
    

    Note : Don't make the test directory in htdocs. Because I haven't tried that yet. These steps worked for me in AMPPS. :)

    Then access 127.0.0.1/wsgi in your favorite browser. You will see Hello World!.

    If you don't see, follow QuickConfigurationGuide

    OR

    You can add these lines in httpd.conf

    
    
        Options FollowSymLinks Indexes
        AllowOverride All
        Order deny,allow
        allow from All
    
    WSGIScriptAlias /wsgi path/to/wsgi_test.wsgi
    
    

提交回复
热议问题