Python 无法通过PyBattle加载静态文件CSS和JS?

Python 无法通过PyBattle加载静态文件CSS和JS?,python,bottle,Python,Bottle,当尝试使用瓶子加载静态文件时,总是得到404。我提到了堆栈溢出问题和谷歌群组聊天,但没有任何东西可以帮助我纠正我的问题。请帮帮我。。花了很多时间在这 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

当尝试使用瓶子加载静态文件时,总是得到404。我提到了堆栈溢出问题和谷歌群组聊天,但没有任何东西可以帮助我纠正我的问题。请帮帮我。。花了很多时间在这

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">
进口瓶
从瓶子进口
从os.path导入basename、abspath、dirname、join
app=瓶子。默认值_app()
appPath=dirname(abspath(“”))
打印应用路径
@瓶子路径(“/”)
def index():
返回瓶子模板('index',dict(title=appPath,get\u url=app.get\u url))
@瓶子路径('/static/:filename#.*.#',name='css')
def服务器_静态(文件名):
return battle.static_文件(文件名,root=join(appPath,'static'))
beggle.debug(True)
运行(host='localhost',port=8082,reloader=True)
**模板:**
添加

在顶端。然后只需使用
静态文件(…,…)
即可:

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