前提・実現したいこと
pythonでflask使って、ローカルでhtmlのサイトを見れるようになったのですが、
.css,.jsが読み込めないです。
app.pyでサーバ起動して、index.htmlまでは見れています。ただその装飾ができていません。
(普通にindex.htmlを開けばしっかり装飾されています)
エラーメッセジーをみると404-で参照できていない感じがします。
参考URL
routingがうまくいってないかと思っています。
とりあえずどれかでroutingできると思い、下のように考えうるところすべてに.cssと.jsを配置してみましたが駄目でした。
index.htmlがあるフォルダと同じところにapp.pyと.js,.css
staticフォルダの中にcssフォルダ(この中に,css)、jsフォルダ(この中に.js),.js,.css
templatesのフォルダの中に.js,index.html,.css
発生している問題・エラーメッセージ
* Serving Flask app "app" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: on * Restarting with stat * Debugger is active! * Debugger PIN: 158-378-258 * Running on http://127.0.0.1:8085/ (Press CTRL+C to quit) 127.0.0.1 - - [21/Nov/2018 16:13:54] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [21/Nov/2018 16:13:54] "GET /style.css HTTP/1.1" 404 - 127.0.0.1 - - [21/Nov/2018 16:13:55] "GET /bluejelly.js HTTP/1.1" 404 -
該当のソースコード
python
1#app.py 2import json 3from flask import request 4from flask import Flask, render_template 5 6app = Flask(__name__) 7 8 9@app.route('/') 10def index(): 11 with open("index.html", "rb") as f: 12 return render_template('index.html') 13 14app.run(debug=True,port=8085) 15print("http://localhost:" + str(port))
試したこと
普通に開く分にはjs,.cssともに動作しています。
ただサーバたてて、localのブラウザでみるとサイトにはアクセスできindex.htmlも見れますが、
.css,.jsが動いていません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。