initializr with bottlepy - css not loaded

时间:2014-07-13 09:49:39

标签: python url-routing bottle static-files initializr

我正在尝试使用从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参数,但无法使其工作。< / p>

整个样板位于html文件夹中,应用程序找到了index.html。我在Firefox和Chrome中试过这个。如果重要的话,我在Win 8.1和anaconda的python 2.7上。我做错了什么?

1 个答案:

答案 0 :(得分:2)

你的路径似乎错了。 CSS路由不应该以{{1​​}}开头,似乎它干扰了Bottle如何解析它。并且您的CSS .根没有正确反映相对于工作目录的static_file文件夹位置。

这应该没问题:

css