1
私のhttpサーバの静的ディレクトリを設定し、その中にいくつかの画像を入れて、ユーザが自分の写真にURLを使用できるようにしたい。しかし、私は失敗しました。以下のコードは動作しません。Tornadoで静的パスを設定する方法は?
# 静态路径
STATIC_DIRNAME = "resources"
# 设置static path
settings = {
"static_path": os.path.join(os.path.dirname(__file__), STATIC_DIRNAME),
}
# and I passed settings to Application
app = tornado.web.Application([
(r"/pictures", handler.PicturesHandler),
], **settings)
静的ディレクトリを "resources"に設定するにはどうしたらいいですか?
(IのようなURLで私の写真を取得したい:localhost:8888/resources/1.jpg
)
私の問題を解決!ありがとうございました。理由を教えてもらえますか? –
@ErumHuangドキュメントhttps://tornado-zh.readthedocs.io/zh/latest/web.html#id2 static_path設定をキーワード引数として送信することで、静的ファイルを提供することができます。/static/URIからこれらのファイルを提供します(これはstatic_url_prefix設定で構成可能です)、同じディレクトリから/favicon.icoと/robots.txtを提供します。 http://www.tornadoweb.org/en/stable/web.html – TaoBeier