Flask is not finding folders and files in Python

后端 未结 1 2050
臣服心动
臣服心动 2020-12-12 08:04

My files structure is following

> code.py

> templates

....> css

....> index.html

相关标签:
1条回答
  • 2020-12-12 09:07

    Flask automatically looks for CSS, JS and other static files in your project root, in the directory:

    /static
    

    More details in the Flask docs here.

    It's good practice to seperate your static files into subdirectories, like so:

    /static/css
    /static/js
    

    In your example, place your CSS at the path:

    /static/css/style.css
    

    Then reference as so in your HTML:

    <link rel="stylesheet" href="/static/css/style.css">
    

    If you're using Jinja2 templates, you can do as described in the documentation:

    {{ url_for('static', filename='style.css') }}
    
    0 讨论(0)
提交回复
热议问题