回答问题

我已经在我的 Win7x64 Xampp 和 Python 2.7 上安装了。

现在我正在尝试获得 Python 语言的“力量”......我该怎么做?

我已经尝试使用 mod_python 和 mod_wsgi,但我的 Python 版本不存在第一个,当我在安装 wsgi 后尝试启动 Apache 时,它给了我一个错误

< Directory "\x93C:/wsgi_app\x94"> path is invalid

我在 < 和 'directory' 之间添加了一个空格,以使字符串在此处可见。

所以...任何人都知道是否有安装这些功能的小教程?

或者有没有人可以逐步解释我该怎么做?

谢谢,对不起,如果我不能解释我。

如果你需要什么,请问我。

Answers

是的,你是对的,mod\python 不适用于 Python 2.7。所以 mod_wsgi 是你的最佳选择。

我会推荐 AMPPS,因为 python 环境默认启用 mod_python 和 python 2.5。AMPPS 网站

如果你还想继续,

在 httpd.conf 中添加这一行

LoadModule wsgi_module modules/mod_wsgi.so

取消注释 httpd.conf 中的行

Include conf/extra/httpd-vhosts.conf

打开 vhost 文件 httpd-vhosts.conf 并添加

NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
    <Directory "path/to/directory/in/which/wsgi_test.wsgi/is/present">
        Options FollowSymLinks Indexes
        AllowOverride All
        Order deny,allow
        allow from All
    </Directory>
    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
</VirtualHost>

在 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]

注意:不要在 htdocs 中创建测试目录。因为我还没有尝试过。这些步骤在 AMPPS 中对我有用。 :)

然后在您喜欢的浏览器中访问 127.0.0.1/wsgi。您将看到 Hello World!。

如果没有看到,请按照QuickConfigurationGuide

或者

您可以在 httpd.conf 中添加这些行

<IfModule wsgi_module>
<Directory path/to/directory>
    Options FollowSymLinks Indexes
    AllowOverride All
    Order deny,allow
    allow from All
</Directory>
WSGIScriptAlias /wsgi path/to/wsgi_test.wsgi
</IfModule>
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐