O'Reilly logo

Instant Flask Web Development by Ron DuPlain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling static files (Simple)

Flask is ready to serve files on your disk from the moment you serve your first request.

Getting ready

Go to your scheduler project and look at the static folder inside the sched directory.

How to do it...

  1. Put the files inside the static folder.
  2. Build URLs for them using flask.url_for('static', filename='path/to/filename') where path/to/filename is the file path inside the static folder, using / regardless of the operating system you are using.

How it works...

By convention, Flask looks for a folder named static next to your application, and serves the files there at the /static/<path:filename> URL, matching all the files in your static folder and its subdirectories. That is, if your application is at app.py, then by default, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required