im a begginer here , struggling with basic stuff
I have my flask:
from flask import Flask , render_template , send_file , send_from_directory
import os
app = Flask(__name__)
#PRIMERA FUNCION
@app.route('/')
def index():
return render_template('prueba.html')
and i have my html :
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CodePen - The Arrow</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<!-- partial:index.partial.html -->
<div class="arrow-1"></div>
<!-- partial -->
</body>
</html>
when I open the html file on browser it shows the css , but when I run flask css doesnt show and I cant figure out why!!!
I have try this
@app.route('/css/<path:filename>')
def css_file(filename):
file_path = os.path.join('css', filename)
return send_file(file_path)
and i also thought it was a problem of my folder layout but I already tried re arrange folders
1条答案
按热度按时间f0ofjuux1#
Flask有不同的方法来实现这一点,但惯例是将静态资产(如CSS)放在
static
目录(应该在项目的根目录)中,并使用Jinja和url_for()
函数将它们链接起来。因此,在您的情况下,它看起来如下所示:Flask docs中有详细说明