6

CGI 環境で bottle.py を使用して、単純なインデックス以上のものを取得/正しく返すのに苦労しています。/hello を返そうとすると、404 応答が返されます。ただし、 /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ファイルです

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

1 に答える 1

4

問題は、<ifmodule>ブロックが Apache サーバーに関連しておらず、mod_rewrite へのディレクティブが機能していないことです。以下から始め.htaccessて、必要に応じて、現在の apache バージョンに従ってブロックを追加します。

DirectoryIndex index.py
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.py/$1  [L]
于 2010-04-19T09:48:21.710 に答える