Uploading Files with Flask - Everything You Need to Know

Опубликовано: 25 Март 2026
на канале: Luke Peters
13,989
357

FULL STACK COURSE (React, Flask, & PostgreSQL): https://lukepeters.me/build-a-full-st...

In this video you'll learn how to upload files using Flask, how to limit file uploads to images only, how to set a maximum upload file size, and how to serve and display uploaded images in a Flask template.

0:00 - Project setup
0:59 - Build the HTML form
2:07 - Create the upload route in Flask
6:10 - Make filenames more secure
8:17 - Make sure a file is selected before uploading
9:16 - Use os.path.join() to improve the code
10:24 - Create app config variables
11:18 - Limit the maximum upload file size
14:18 - Only allow images to be uploaded
17:18 - Display uploaded images in the template
24:35 - Ideas for future improvements

---------------------------------------------------------------
PROJECT CODE (STYLES.CSS INCLUDED)

https://github.com/LukePeters/flask-f...

---------------------------------------------------------------
RECOMMENDED WEB HOSTING

I swear by Linode. I've been using them for years and I refer every freelance client to them. Here's my special referral link if you want to help me out a little: https://lukepeters.tech/linode

---------------------------------------------------------------
MY DESK SETUP GEAR (affiliate links)

⌨️ Keyboard – https://amzn.to/3sR3WEK

🖱 Mouse – https://amzn.to/3aEBvnc

🖥 Monitor – https://amzn.to/30pmuzd

🦾 Monitor Mount/Arm – https://amzn.to/3sLd3Xu

🎤 Microphone – https://amzn.to/3sRfxUb

🦾 Microphone Arm – https://amzn.to/3xrxImT

🎛 Microphone Processor – https://amzn.to/3gConme

⚡️ Thunderbolt Dock – https://amzn.to/3aE8aJC

🔊 Speakers – https://amzn.to/3nip0D0

🎧 Headphones – https://amzn.to/3xoCVfm

🪑 Chair – https://amzn.to/3eBIw9I