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

发布于 2024-09-16 18:05:11 字数 1219 浏览 1 评论 0原文

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

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

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

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

但这将捕获(至少在开始时)每个可能的 URL,并且我只希望通过“index”处理对域根的访问。哈尔普?

一些基本信息:

Python 2.6、web.py 0.3、Apache 2.2 with mod_wsgi

不确定还有什么有用的,所以如果有什么重要的东西我可以添加(也许来自 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>

So every web.py tutorial I've seen includes this line:

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

And then, later on, the index class is defined with a GET function and so on. My problem is, this doesn't work. Using the code above, I get a 404 error. Using the following mapping works:

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

But that's going to catch, at least at first, every single possible URL, and I want only an access to the domain root to be handled by "index." Halp?

Some basic info:

Python 2.6, web.py 0.3, Apache 2.2 with mod_wsgi

Not sure what else would be useful, so if there is something important I can add (the VirtualHost from Apache, maybe?) please ask and I'll add it here.

EDIT: Including my Apache VirtualHost config:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅沫记忆 2024-09-23 18:05:11

如需了解背景信息,请阅读:

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 的多种方法,这是不应该的一起使用。

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

For background read:

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

Presuming you only have the one WSGI application to be mounted at root of site and only static files or other resources are under /static, then instead of:

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>

use:

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>

You are mixing up multiple ways of configuring mod_wsgi which shouldn't be used together.

If your requirements are something else, you are going to have to be clearer about what you want to happen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文