2010-04-18 58 views
6

我一直在獲取任何東西比簡單的索引/在CGI環境中使用bottle.py正確返回。當我嘗試返回/你好,我得到一個404響應。但是,如果我要求/index.py/hello使用CGI和Bottle.py路由URL的問題

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

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

我複製許多代碼從這裏我使用DH,似乎有關:http://blog.coderonfire.com/2010/02/running-bottle-python-micro-framework.html

感謝您的幫助。

回答

4

問題是<ifmodule>塊與您的Apache服務器無關,並且mod_rewrite指令無法正常工作。從以下.htaccess開始,然後如果您有需要,請根據當前的apache版本添加該塊。

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

謝謝,這個工程。我不得不刪除上/ on /index.py/$1,但它完美的作品。 – Risingson 2010-04-19 12:46:50

+0

@enrico,我不確定我喜歡你的編輯。我最好刪除前導斜槓而不是刪除RewriteBase。 – newtover 2013-10-30 07:38:54

+0

設置當它只是一個斜槓時,RewriteBase似乎過分,但如果這種情況發生變化,肯定會使事情變得更加容易。但是,我並沒有刪除前導斜槓的真正原因是編輯需要至少6個字符,這是因爲缺乏「重要編輯」過濾器。如果這是您的偏好,您可以放回去並刪除斜槓。 – Enrico 2013-10-30 21:54:04