Web.py URL 映射不接受 '/'
所以我见过的每个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如需了解背景信息,请阅读:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines假设
您只有一个 WSGI 应用程序要安装在站点根目录下,并且只有静态文件或其他资源位于 /static 下,则不要使用:
使用:
您正在混合配置 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:
use:
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.