烧瓶和CSS的麻烦

时间:2012-12-21 19:14:35

标签: python css flask

我有以下项目结构:

templates
    index.html
static
    style.css
testFlask.py

我尝试添加style.css(使用url_for或手动添加),但网址localhost:5000/static/style.cssPage not found

此处来自testFlask.py的代码:

from flask import Flask, render_template, request, session, g, redirect, url_for,flash
app = Flask(__name__)

@app.route('/', methods=['GET'])
def index():
    return render_template('index.html')

index.html的代码:

<head>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>

最后,我重新创建了我的style.css,现在每个人都很好。 感谢您的关注!

1 个答案:

答案 0 :(得分:1)

我在这里使用flask 0.8(Debian软件包中的版本)测试了你的代码/模板片段,我无法重现这个问题 - &gt;找到了style.css。 也许静态目录的权限是限制性的?如果我删除了运行testFlask.py的用户对静态目录的读访问权,则会显示404。

最好的祝福, 的Matthias