Upload Profile Picture - Flask Fridays #38

Codemy.com January 8, 2022
Video Thumbnail
John Elder Logo

John Elder

@johnelderai

About

AI is taking over the world...let's get into it! OpenClaw, Claude Code, Manus, Perplexity, and whatever other weird AI stuff that comes along with a pinch of Python Programming thrown in from time to time. Check out my website JohnElder.AI and Codemy.com for more videos!

Video Description

** ERROR UPDATE! - There's an error in the code preventing saving the profile pic: saver.save(os.path.join(app.config['UPLOAD_FOLDER']), pic_name) should be: saver.save(os.path.join(app.config['UPLOAD_FOLDER'], pic_name)) In this video I'll show you how to upload profile pics with Flask! We aren't going to save them to the database, we'll save the images to our static/images folder and create unique usernames for them. We'll also learn how to use UUID and UUID1 to create unique profile pic names, and why that's important! #flask #codemy #JohnElder Timecodes 0:00​​ - Introduction 2:56 - Add Profile_Pic Field To Form 3:38 - Update Dashboard Form 4:40 - Add Profile_Pic Field To User Model 5:46 - Migrate The Database 6:45 - Get Profile Pic Form Data 7:16 - Change Form Enctype 8:00 - Add Profile Pic Name To Dashboard 9:13 - Save Image Name To Database 9:40 - Import Secure_Filename, OS, and uuid 10:39 - Grab Image Name 11:17 - Add UUID To Image Name 13:07 - Save New UUID Image Name To Database 14:32 - Save Image To Images Folder 15:26 - Set Upload Folder Config Variable 16:26 - Save The File 18:15 - Error Handling 19:12 - Conclusion

Boost Your Flask Skills

AI-recommended products based on this video

Loading...
HAUSOURCE Full Bed Frame with 4 Storage Drawers Bed Frame Full Size with Headboard LED Lights Charging Station Metal Slats Platform Heavy-Duty Support No Box Spring Needed White

HAUSOURCE Full Bed Frame with 4 Storage Drawers Bed Frame Full Size with Headboard LED Lights Charging Station Metal Slats Platform Heavy-Duty Support No Box Spring Needed White

(1,086)
$329.99
Only 5 left in stock.
Loading...
VASAGLE LED Bed Frame Full Size, Storage Headboard and Charging Station, Full Bed Frame with 2 AC Outlets, 1 USB Port, 1 Type-C Port, No Box Spring Needed, Dove Gray and Camel Brown URMB842G01

VASAGLE LED Bed Frame Full Size, Storage Headboard and Charging Station, Full Bed Frame with 2 AC Outlets, 1 USB Port, 1 Type-C Port, No Box Spring Needed, Dove Gray and Camel Brown URMB842G01

(108)
$1,543.78
FREE delivery Jun 20 - Jul 2Only 3 left in stock.
Loading...
VASAGLE LED Bed Frame Queen Size, Storage Headboard and Charging Station, Queen Bed Frame with 2 AC Outlets, 1 USB Port, 1 Type-C Port, No Box Spring Needed, Ink Black and Rustic Brown URMB841B01

VASAGLE LED Bed Frame Queen Size, Storage Headboard and Charging Station, Queen Bed Frame with 2 AC Outlets, 1 USB Port, 1 Type-C Port, No Box Spring Needed, Ink Black and Rustic Brown URMB841B01

(162)
$249.99
FREE delivery Jun 20 - 30
Loading...
Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)

Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)

(103,365)
$13.49
5K+ bought in past month
Loading...
Carplay Cable Car Charger Cord for iPhone 16/15 Pro/Max/Plus/16e, for Apples iPad, Pixel 9/8/7, Galaxy S24/S23/S22, Android Phone, USB A to USB C Cable 3FT Charging & Sync Car Accessories 2Pack

Carplay Cable Car Charger Cord for iPhone 16/15 Pro/Max/Plus/16e, for Apples iPad, Pixel 9/8/7, Galaxy S24/S23/S22, Android Phone, USB A to USB C Cable 3FT Charging & Sync Car Accessories 2Pack

(273)
$13.99
FREE delivery Sat, Jun 14 on your first order
100+ bought in past month
Loading...
iPhone Charger [Apple MFi Certified] 3FT, 3Pack USB A to Lightning Cable Braided Fast Charging Apple Cord Compatible with iPhone 14 13 12 11 Pro Max XS XR X 8 7 6 5 Plus iPad/iPod/AirPods

iPhone Charger [Apple MFi Certified] 3FT, 3Pack USB A to Lightning Cable Braided Fast Charging Apple Cord Compatible with iPhone 14 13 12 11 Pro Max XS XR X 8 7 6 5 Plus iPad/iPod/AirPods

(5,626)
$17.99
FREE delivery Sat, Jun 14 on your first order
50+ bought in past month
Loading...
16.4Ft/5M Long USB C Cable, Durable USB A to USB C Charging and Data Sync Cord, Power Extension Cable for Any USB-C Enabled Security Cameras Phones Tablets Switch Pro Controller and More

16.4Ft/5M Long USB C Cable, Durable USB A to USB C Charging and Data Sync Cord, Power Extension Cable for Any USB-C Enabled Security Cameras Phones Tablets Switch Pro Controller and More

(95)
$11.99
FREE delivery Sat, Jun 14 on your first order
Loading...
Socket Fan Light, Eonini 2-in-1 Small Ceiling Fan with Lights and Remote, 3 Colors Dimmable LED Light Bulb Fan, 1000LM, Easy Install Screw-in E26 Base for Bedroom Kitchen Garage Living Room

Socket Fan Light, Eonini 2-in-1 Small Ceiling Fan with Lights and Remote, 3 Colors Dimmable LED Light Bulb Fan, 1000LM, Easy Install Screw-in E26 Base for Bedroom Kitchen Garage Living Room

(3)
$59.99
FREE delivery Wed, Aug 20
200+ bought in past month
Loading...
HJTHJT 500ML Essential Oil Diffuser: Aroma Diffuser with Remote Control for Hotel Spa Yoga Room - Humidifier with 14 Colors LED Night Light for Bath Bedroom Relaxation (Dark Black)

HJTHJT 500ML Essential Oil Diffuser: Aroma Diffuser with Remote Control for Hotel Spa Yoga Room - Humidifier with 14 Colors LED Night Light for Bath Bedroom Relaxation (Dark Black)

(77)
$36.99$35.14
FREE delivery Mon, Jun 16
200+ bought in past month
Loading...
2026 Smart Nail Clipper for Seniors - Electric Nail Clippers,Electric Nail Clipper with LED Light, Painless Toenail Trimmer for Thick Nails, Arthritis, Low Vision (Gray)

2026 Smart Nail Clipper for Seniors - Electric Nail Clippers,Electric Nail Clipper with LED Light, Painless Toenail Trimmer for Thick Nails, Arthritis, Low Vision (Gray)

(4)
$23.99
$9.99 delivery Feb 13 - 25
Loading...
Whitebite Pro Upgraded Teeth Whitening Kit with Pens for Sensitive Teeth: Teeth Whitening LED Light, Mouth Tray, Carbamide Peroxide Whitening Gel

Whitebite Pro Upgraded Teeth Whitening Kit with Pens for Sensitive Teeth: Teeth Whitening LED Light, Mouth Tray, Carbamide Peroxide Whitening Gel

(131)
$39.99
FREE delivery Sat, Nov 22
Loading...
LEGO Speed Champions Oracle Red Bull Racing RB20 F1 Race Car Model Kits - Building Set for Adults, Ages 18+ with Realistic Features - Red Bull F1 DIY Crafts for Display - Gift Idea for F1 Fans - 77243

LEGO Speed Champions Oracle Red Bull Racing RB20 F1 Race Car Model Kits - Building Set for Adults, Ages 18+ with Realistic Features - Red Bull F1 DIY Crafts for Display - Gift Idea for F1 Fans - 77243

(353)
$29.98$29.53
FREE delivery Sat, Jun 14 on your first order
1K+ bought in past month
Loading...
Alpen Muesli No Sugar Added Breakfast Cereal, High in Fibre, Low Sodium, Non-GMO Project Verified, Regular Size 600g

Alpen Muesli No Sugar Added Breakfast Cereal, High in Fibre, Low Sodium, Non-GMO Project Verified, Regular Size 600g

(30)
$5.97
FREE delivery Sun, Mar 29 on your first order
400+ bought in past month