Flask の静的ファイルの取り扱い
昨日遭遇した現象。
仕様なのこれ?
app.py
#!/usr/bin/env python # -*- coding: utf-8 -*- from flask import Flask, render_template app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/<arg1>/<arg2>/<arg3>/', strict_slashes=False) def sample(arg1, arg2, arg3): print arg1, arg2, arg3 return render_template('index.html') if __name__ == '__main__': app.run(debug=True)
index.html
<!doctype html> <head> <meta charset="utf-8"> <title>Sample</title> <link rel=stylesheet type=text/css href="/static/css/style.css"> </head> <body> <div class="container">foo</div> </body> </html>
http://localhost:5000/ にアクセスするとちゃんと CSS が適応された状態で表示される。
http://localhost:5000/foo/bar/baz/ にアクセスすると、CSS が適応されない。
で、css のリクエストが def sample() の方にディスパッチされてる。
* Running on http://localhost:5000/ * Restarting with reloader foo bar baz 127.0.0.1 - - [30/Sep/2011 23:17:14] "GET /foo/bar/baz/ HTTP/1.1" 200 - static css style.css 127.0.0.1 - - [30/Sep/2011 23:17:14] "GET /static/css/style.css HTTP/1.1" 200 -
これどうやったら、css のアクセスは static の方をみるようになるんだろう?