gpt4 book ai didi

python - Web.py URL 映射不接受 '/'

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:13 27 4
gpt4 key购买 nike

所以我看到的每个 web.py 教程都包含这一行:

urls = (
'/', 'index',
)

然后,稍后,使用 GET 函数等定义索引类。我的问题是,这不起作用。使用上面的代码,我收到 404 错误。使用以下映射工作:

urls = (
'/.*', 'index',
)

但这至少在开始时会捕捉到每一个可能的 URL,而且我只希望通过“索引”处理对域根的访问。暂停?

一些基本信息:

Python 2.6、web.py 0.3、带有 mod_wsgi 的 Apache 2.2

不确定还有什么有用的,所以如果我可以添加一些重要的东西(也许是来自 Apache 的 VirtualHost?)请询问,我会在这里添加。

编辑:包括我的 Apache VirtualHost 配置:

<VirtualHost *:80>
ServerName dd.sp4.us
DocumentRoot /home/steve/www/nov2010/public/
ErrorLog /home/steve/www/nov2010/log/error.log
CustomLog /home/steve/www/nov2010/log/access.log combined

WSGIScriptAlias / /home/steve/www/nov2010/app
Alias /static /home/steve/www/nov2010/public

<Directory /home/steve/www/nov2010/app>
SetHandler wsgi-script
Options ExecCGI
</Directory>

AddType text/html .py

<Location />
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/static
RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
RewriteRule ^(.*)$ code.py/$1 [PT]
</Location>
</VirtualHost>

最佳答案

背景阅读:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines

假设您只有一个 WSGI 应用程序要挂载在站点的根目录下,并且只有静态文件或其他资源在/static 下,那么代替:

WSGIScriptAlias / /home/steve/www/nov2010/app
Alias /static /home/steve/www/nov2010/public

<Directory /home/steve/www/nov2010/app>
SetHandler wsgi-script
Options ExecCGI
</Directory>

AddType text/html .py

<Location />
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/static
RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
RewriteRule ^(.*)$ code.py/$1 [PT]
</Location>

使用:

Alias /static /home/steve/www/nov2010/public

WSGIScriptAlias / /home/steve/www/nov2010/app/code.py

<Directory /home/steve/www/nov2010/app>
Order allow,deny
Allow from all
</Directory>

您混合了多种配置 mod_wsgi 的方法,不应一起使用。

如果您的要求是其他的,您将必须更清楚您想要发生什么。

关于python - Web.py URL 映射不接受 '/',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3613594/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com