1

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

ボトルはそれ自体では静的ファイルを提供しないことを理解しており、ルートをserver-staticいじって引数を追加、変更、および削除しましたが、動作さmimetypeせることができません。

ボイラープレート全体がhtmlフォルダーにあり、アプリはindex.html. FirefoxとChromeでこれを試しました。私はWin 8.1とanacondaのpython 2.7を使用しています。私は何を間違っていますか?

4

1 に答える 1

2

あなたの道は間違っているようです。CSS ルートは で始まるべきではありません.。ボトルがそれを解析する方法を妨げているようです。また、CSSルートは、作業ディレクトリに対するフォルダーの配置をstatic_file適切に反映していません。css

これはうまくいくはずです:

@route('/css/<filename>')
def server__static(filename):
    return static_file(filename, root='./html/css')
于 2014-07-13T10:59:39.247 に答える