flâneur — a map of the web's best reading

OpenTechSchool – Files & Templates

opentechschool.github.io · 935 words · saved by 1 readers

So you’ve seen how to send out some basic text with a simple Flask application, and the languages that are used to build the web: HTML, CSS and Javascript. Serving text isn’t enough though - what if we want to serve some actual files? Luckily, Flask comes prepared. All you have to do is create a folder in the same directory as catseverywhere.py with the special name of static. Any file you put in that folder will be served by Flask automatically! It’s one of the nice functionalities provided to you by Flask’s authors. You can do this with your computer’s file browser, or on the command line by typing mkdir static. So, if you made a file in the static folder called cats.gif, and you’d normally access your application by visiting the url http://127.0.0.1:5000, then you can view that file by going to http://127.0.0.1:5000/static/cats.gif. Check this works for you by downloading a funny image from the internet (there are plenty at imgur), putting it in the static folder, running your Flask

OpenTechSchool – Files & Templates OpenTechSchool Websites with Python Flask Files & Templates Home Core Setting up Hello, World! Languages of the Web Files & Templates Forms Form Submission Data Structures Extras Learning HTML and CSS Professional CSS Keeping track of users Using a database Hosting on Heroku Files So you’ve seen how to send out some basic text with a simple Flask application, and the languages that are used to build the web: HTML, CSS and Javascript. Serving text isn’t enough though - what if we want to serve some actual files? Luckily, Flask comes prepared. All you have to d

Explore this link on the map →

related reading