无法访问静态文件

时间:2019-05-08 06:04:20

标签: flask jinja2

将烧瓶应用程序路由到子页面(例如“批处理”

)时,我无法访问静态文件

我的代码如下:

def batch(batch_name):
    try:
        if 'username' in session:
            #something here
            return render_template("batch.html", something = something)
        return redirect(url_for('login'))

    except Exception as e:
        return render_template("500.html", error = str(e))

Jinja模板是:

        <li><a href="batch/{{ batch_name }}">{{ batch_name }}</a></li>
        {% endfor %}

当我尝试像batch_name

一样工作时,一切正常

运行此命令时的输出:

127.0.0.1 - - [08/May/2019 11:27:12] "GET /batch/static/js/json-app.js HTTP/1.1" 404 -

为什么将此\batch添加到static_url之前

我尝试了

        <li><a href="{{ batch_name }}">{{ batch_name }}</a></li>
        {% endfor %}

它工作正常,但我需要我的网址像http://localhost:5000/batch/Oct-batch而不是http://localhost:5000/Oct-batch

1 个答案:

答案 0 :(得分:0)

现在我要弄坏键盘,才意识到我需要在静态文件url中添加一个/

小的调整改变了一切。就我而言,解决方案是app Flask(__name__, static_url_path='/static')<link rel="stylesheet" href="/static/css/custom.css

相关问题