本文介绍了使用CGI和Bottle.py路由的URL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有困难得到更多的东西比一个简单的索引/使用bottle.py在CGI环境中正常返回。当我尝试返回/你好,我得到一个404响应。不过,如果我要求/index.py/hello

I've been having difficulty getting anything more than a simple index / to return correctly using bottle.py in a CGI environment. When I try to return /hello I get a 404 response. However, if I request /index.py/hello

import bottle
from bottle import route

@route('/')
def index():
    return 'Index'

@route('/hello')
def hello():
    return 'Hello'

if __name__ == '__main__':
    from wsgiref.handlers import CGIHandler
    CGIHandler().run(bottle.default_app())

和这里是我的.htaccess文件

And here is my .htaccess file

DirectoryIndex index.py
<ifmodule mod_rewrite.c="">
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.py/$1  [L]
</ifmodule>

我复制多的code,从这里我使用的DH,它似乎有关:<一href="http://blog.$c$cronfire.com/2010/02/running-bottle-python-micro-framework.html">http://blog.$c$cronfire.com/2010/02/running-bottle-python-micro-framework.html

感谢您的帮助。

推荐答案

的问题是,&LT; ifmodule&GT; 块是不相关的Apache服务器和指令到了mod_rewrite不工作。先从以下的.htaccess ,然后如果你有需要,根据您当前的Apache的版本中添加块。

The problem is that the <ifmodule> block is not relevant to your Apache server and the directives to mod_rewrite are not working. Start with the following .htaccess and then if you have a need, add the block according to your current apache version.

DirectoryIndex index.py
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.py/$1  [L]

这篇关于使用CGI和Bottle.py路由的URL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:28