4

given a structure like inside a directory foo:

/web
    /static
        /css
        /img
/model
runapp.py

How to server static files from web/static/css or /img

like

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

It gives

werkzeug.routing.BuildError
BuildError: ('web/static', {'filename': 'css/bootstrap.min.css'}, None)

I have done

app = Flask(__name__, static_folder=os.path.join(os.getcwd(),'web','static'), static_url_path='')

but it doesn't work. and btw whats the difference between static_folder and static_url_path ?

3
  • 1
    this any help? Commented May 3, 2015 at 13:04
  • 1
    btw whats the difference between static_folder and static_url_path ?. You can find the answers here Commented May 3, 2015 at 14:19
  • @PaulRooney is it <path:filename> or <filename:path> because ver .10 shows the former pattern. Commented May 3, 2015 at 15:29

1 Answer 1

4

url_for('web/static') won't work because 'static' is a special blueprint for serving static files. So do this:

url_for('static', filename='css/bootstrap.min.css')

And set the static folder in your app:

app = Flask(__name__, static_folder=os.path.join(os.getcwd(),'web','static'))

static_url_path defaults to the name of static_folder. Not sure how setting it to '' would help.

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

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.