【发布时间】:2014-07-13 09:49:39
【问题描述】:
我正在尝试使用从Initializr 下载的样板和bottle.py。我显然做错了,因为当我只是尝试加载 index.html 时,站点呈现而不使用任何样式表,并且在浏览器控制台中出现以下错误:
Use of getUserData() or setUserData() is deprecated. Use WeakMap or element.dataset instead. requestNotifier.js:52
The stylesheet http://localhost:8080/css/normalize.min.css was not loaded because its MIME type, "text/html", is not "text/css". localhost:8080
The stylesheet http://localhost:8080/css/main.css was not loaded because its MIME type, "text/html", is not "text/css". localhost:8080
SyntaxError: syntax error modernizr-2.6.2-respond-1.1.0.min.js:1
SyntaxError: syntax error plugins.js:1
SyntaxError: syntax error
我的应用如下所示:
import bottle # Web server
from bottle import run, route, static_file, error, template # import request
@route('/')
def index():
return static_file('index.html', root='./html/')
@route('./css/<filename>')
def server__static(filename):
return static_file(filename, root='./css/')
if __name__ == '__main__':
# To run the server, type-in $ python server.py
bottle.debug(True) # display traceback
run(host='localhost', port=8080, reloader=True)
样式表是从index.html 调用的,如下所示:
<link type="text/css" rel="stylesheet" href="css/normalize.min.css">
<link type="text/css" rel="stylesheet" href="css/main.css">
我的基本文件夹结构是(剪断的 js 文件夹等):
bottle_test.py
- html
index.html
- css
main.css
normalize.min.css
我知道 bottle doesn't serve static files 本身,我确实玩弄了到 server-static 的路线,并添加、更改和删除了 mimetype 参数,但无法让它工作。
整个样板文件位于html 文件夹中,应用程序确实找到了index.html。我在 Firefox 和 Chrome 中试过这个。如果重要的话,我在 Win 8.1 和 anaconda 的 python 2.7 上。我做错了什么?
【问题讨论】:
标签: python url-routing bottle static-files initializr