4

I am unable to find exact path of .css file in my flask app. Following is relevant code

layout.html

<!DOCTYPE html>
<html>
<head>
    <title>An App</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
    <div id="container">
        <div id="heading"><h3>App</h3></div>
        {% block content %}{% endblock %}
    </div>
</body>
</html>


+app
  +static
    style.css
+templates
__init__.py
forms.py
models.py
views.py
db_repository
.gitignore
app.db
config.py
db_create.py

The one with + sign are folders

Update:

I tried this in __init__.py, same result

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
import os
app = Flask(__name__)
app.config.from_object('config')
app._static_folder = os.path.abspath("static/style.css")
print os.path.abspath(app._static_folder)
db = SQLAlchemy(app)

from app import views, models

The link http://127.0.0.1:5000/static/style.css gives 404 error

2
  • try adding the path when u create the app,app._static_folder = <path_to_static_directory> Commented Nov 7, 2014 at 7:36
  • @sk11 question updated. Still same issue. Commented Nov 7, 2014 at 9:55

2 Answers 2

11

Static should be on the same level as templates, not under app. Have you tried that?

Sign up to request clarification or add additional context in comments.

1 Comment

You were right. I did not notice static one was out of app folder thus different from templates
9

I you want to change the route to the static asset's folder you could do:

app = Flask(__name__, static_folder='app/static')

check this here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.