1

ボトルを使用して静的ファイルを読み込もうとすると、常に 404 が発生します。スタック オーバーフローの質問と Google グループ チャットを参照しましたが、問題を解決するのに何の助けにもなりません。私を助けてください..これに多くの時間を費やしました...

Tuts
   main.py
   static/
     bootstarp.css
   views/
     index.tpl

main.py コード

import bottle
from bottle import Bottle
from os.path import basename,abspath, dirname, join

app = bottle.default_app()

appPath = dirname(abspath(''))
print appPath

@bottle.route('/')
def index():
    return bottle.template('index', dict(title=appPath,get_url=app.get_url))

@bottle.route('/static/:filename#.*#', name='css')
def server_static(filename):
    return bottle.static_file(filename, root=join(appPath,'static'))

bottle.debug(True)
bottle.run(host='localhost', port=8082,reloader=True)


**Template:**

<link href="{{ get_url('css', filename='bootstrap.css') }}" rel="stylesheet" media="screen">
4

1 に答える 1

0

追加

from bottle import static_file

上部に。次に、使用するだけstatic_file(..., ...)で問題ありません。

@bottle.route('/static/:filename#.*#', name='css')
def server_static(filename):
    return static_file(filename, root=join(appPath,'static'))
于 2013-01-25T09:58:37.320 に答える