2017-04-10 2 views
0

플라스크 작업을 시작했습니다. 문제는 정적 폴더에 CSS 파일을 만들고 템플릿에 해당 CSS 파일을로드하려고했습니다.Flask가 CSS 파일을로드하지 않습니다

시크릿 모드에서이 파일을로드해도 캐시 문제 일 수 있다고 생각되지만 그렇지 않습니다.

<!DOCTYPE html> 
<title> Welcome to My Blog</title> 

<link rel="stylesheet" type="=text/css" href="{{ url_for('static', filename='style.css?v=0.01') }}"> 

<h2>Hey there {{ name }}</h2> 

Image :Hello world flask app

Blog.py

from flask import Flask, request, render_template 

app = Flask(__name__) 


... 
@app.route('/profile/<username>') 
def profile(username): 
    return render_template("profile.html", name=username) 

... 

if __name__ == '__main__': 
    app.run(debug=True, port=8080) 

있는 style.css

h2{ 
    color: #00bfff; 
} 
+0

'blog.py'의 내용은 무엇입니까? '앱'을 어떻게 설정합니까? – Vallentin

+0

고마워, 내가 blog.py을 추가했습니다 – burc

답변

1

문제는 당신이 당신의 이름의 쿼리 문자열을 포함하는 것입니다. static/style.css%3Fv%3D0.01에서

url_for('static', filename='style.css?v=0.01') 

URL 경로 결과, 특수 문자 인코딩 얻을 때문이다. 이 문제를 해결하려면 키워드 인수로 쿼리 요소를 추가해야합니다 또한

url_for('static', filename='style.css', v=0.01) 

:

  • 파일은 stye.css라고하지 style.css
  • 귀하의 <link> 태그 type="=text/css"라고하지 type="text/css"
  • 을해야으로
+0

나는 그것을 변경했지만 여전히 동일합니다. – burc

+0

내가 열려고 할 때; http://127.0.0.1:8080/static/style.css?v=0.01 오류가 없습니다. – burc

+0

나는 이름을 변경하고 다시 실행했지만 여전히 오류가 발생합니다. 질문에 style.css 파일을 추가했습니다. – burc

관련 문제