In 2024, this is still the best Flask tutorial on the Internet due to its comprehensive coverage of topics, clear explanations, and up-to-date practices.
I'm in my final semester of my degree right now! and the first thing I am going to do as soon as I land a job is to support this channel! This series is just AMAZING!
Corey! I have an interview tomorrow wish me luck! If I get this job the first thing I'll do is support you through Patreon with my first salary. You have taught things so efficiently that no professor has ever taught in these semesters for graduation. You're such a kind person for teaching such valuable content with this brilliant quantity without charging a penny!
@@soumyajitdey5720 What path would you recommend (or did you take) on your way to becoming a data engineer? Also I'd like to connect with you on LinkedIn or an other social platform. Thanks!
For anyone wanting to delete the previous profile picture while adding a new one, I added this just before the return statement in the save_picture function: prev_picture = os.path.join(app.root_path, 'static/profile_pics', current_user.image_file) if os.path.exists(prev_picture): os.remove(prev_picture)
The code for anyone who wants to delete the previous profile picture (but never delete the default.jpg) while adding a new one, please add the below code block before the return statement inside the save_picture function: # Code Block Starts prev_picture = os.path.join(app.root_path, 'static/profile_pics', current_user.image_file) if os.path.exists(prev_picture) and os.path.basename(prev_picture) != 'default.jpg': os.remove(prev_picture) # Code Block Ends
@@heisenburgfreed7591 could just do and current_user.image_file != 'default.jpg': either one works. Yours kinda keeps it more consistent with the os.path thing Thanks OP. Was struggling with this before this comment.
Can anyone clarify if the profile picture is being fetched from the server or from the local filesystem (when GET request is called on the account page)? To me it seems like while the file name is sent to the SQL database, the actual image isn't being sent to the database at all?
@@xtrzne A little late, but I'll answer for those who wonder. After a picture is selected from a local file system on the webpage, it's being put (its resized copy) onto the local filesystem *by the server* (which is now being run locally) into *static/profile_pics* directory. Only the filename goes into the database. It's often a bad thing to store bitmaps in the database as blobs.
loving this tutorial! i added the code to delete the old profile pic when updating with a new one. this is the if statement in the account function in routes.py ``` if form.picture.data: old_pic = current_user.image_file picture_file = save_picture(form.picture.data) current_user.image_file = picture_file if old_pic != 'default.jpg': os.remove(os.path.join(app.root_path, 'static/profile_pics', old_pic)) ```
Thank you for the best content when it comes to python and Flask tutorials. I tried to learn Flask a little too early in my programming journey and when i was stuck i started to search for another tutorial instead of improving my skills. I came back crawling to you Corey QUICK. Thank you!
I have no experience using any backend framework, except some basic django... I did not expect such an amazing quality from a RUclips tutorial, which is free! thankyou! this is an amazing series! you're god sent for broke students!
Hello, my name is Pedro and I live in São Paulo, I am writing this text to thank you immensely because you are not only helping me in my professional life but also in my academic life. Keep being this amazing person that you are and may there be others like you over the years, thank you very much.
Duuuuuuuuuuuude, you're a beeeaaaaaaaaaast ! Your tutorials are awesome ! keep the good work ! If you could put a series about Laravel that would be dope ! You got some high quality skills in teaching ! Thanks a lot !
Corey, Your python videos are really amazing. I started python programming after a decade and I'm into it now. But my job is mostly in automation testing. Wanted to change to development and picked your series. Can't stop in btw, yesterday I started and now I'm in part 7. With this video reference, I can able to build the website. Amazing Work!!
Another LEGENDARY vid! When I saw you install Pillow, I thought to myself "Python is like the car, and these extensions are like aftermarket parts... " :)
In order to make the picture upload work on the current version of Python and Flask, in "forms.py" I had to change: [code] picture = FileField('Update profile picture', validators=[FileAllowed('jpg', 'png')]) [/code] to: [code] picture = FileField('image', validators=[FileRequired(), FileAllowed(['jpg', 'png'], 'Images only!')]) [/code] Last but not least, thank you for the great series!
I think you only had a problem because you forgot to put the file types into a list. [FileAllowed('jpg', 'png')]) should have been [FileAllowed(['jpg', 'png'])]). He had the brackets correct in the video and it worked for me on the newest version. When I was following along I wasnt expecting to have to use the list, so I'm guessing you thought the same and didn't notice him do it.
For the profile picture @21:57 , I had to change picture = FileField( 'Update Profile Picture', validators= [ FileAllowed ( [ 'jpg', 'png' ] ) ] ) to picture = FileField( 'Update Profile Picture', validators=[ FileRequired(), FileAllowed ( [ 'jpg', 'png' ] ) ] ) and also import FileRequired at the starting of the file. maybe because I'm using Python3.5 and not 3.6 Thanks for the awesome tutorials @CoreySchafer
as a zero knowledge person about coding, i wonder how did I able to go this far in the series(Part 8) and be able to successfully roll out the apps. Thank you for these videos. I am very excited finishing this apps.
This videos are amazing and complete, support this channel is a must! Just a question for the audience, to see if someone is having the same problem: - On the account route, when updating the current_user.name and current_user.email with the form data, then doing the db.session.commit() is not updating the DB but the commit returns None as if everything was Ok, has somebody run into the same problem?? Thank you very much again!
Just fyi, this video used picture_path = os.path.join(app.root_path + "static/profile_pics" + picture_fn) Corey is using mac, and it works for him, but for people using windows please use: picture_path = os.path.join(app.root_path + r"\static\profile_pics\\" + picture_fn)
Thanks for catching that! I think the best solution is to simply pass in static and profile_pics as different arguments like so... picture_path = os.path.join(app.root_path, "static", "profile_pics", picture_fn) I will issue a correction in the next video I add to this series. Thanks again!
Yup, join should take care of that. Thanks for these tutorials Corey. Really appreciate em. I am not as fast as the other guys, who finished these tutorials in a day or two. I am on week two. :)
29:00 - Even though the likelihood of two 8-byte numbers being the same is astronomical, might as well check to make sure the image doesn't already exist and if so, regenerate a new hex.
Ha! When I got to that part I thought the same thing and immediately checked the comments to see if anyone else did too... Agree that it's incredibly unlikely, but better safe than sorry.
@@BtheDUB Actually you would probably have to check the profile_pics folder with the os.listdir() function and compare them to generated hex. If the file already exists, regenerate new hex. But as been told, that's not very likely.
Wow, thank you for these great videos! I mostly program as a hobby, and have had trouble finding good resources on web development, and was honestly quite intimidated, but you, as always, provide a great series! I have a question about the render_template() function: what determines whether or not you need to pass a variable to it? For example, `title` and `image_file` are passed in, but current_user isn’t, but still works fine in the template. Thank you again!
These are all optional parameters and are autoscaled into the function as context variables. The only required parameter is the resource template which is our actual html. The rest can be left out and can be either made use of or ignored. render template is coded to be as flexible as possible hence the use of autoscaping here (**). Its why that one function works for, taking in as many parameters as needed without needing restructuring of the function.
For those wondering how to remove the previous image from the profile_pics directory after updating the profile picture. It's just as simple as adding this line in the save_picture() function: - if current_user.image_file != 'default.jpg: os.remove(os.path.join(app.root_path, 'static/profile_pics', current_user.image_file)) It has be added before this line: - i.save(picture_path) Let me know if someone find another solution!
Hi Corey, Excellent video, this was extremely helpful! Can you add a quick video to show us how we can add pictures and video files to each post? I would like the user to have the ability to include photos from their desktop and add to their posts. I love that they can add photos to their profile and would like to provide the option for them to include photos within their posts as well. Thanks so much!!
Something that I noticed is Emails are NOT case sensitive and that should be taken into account when making a website that requires email or else people can sign up for multiple account using same email by changing capitalization their email.
I really love the series and am really having fun, I just have one question on this module though...I thought we will be sending the images the users upload to the database, why are we sending them to the static folder? Is this how real world web apps work, or is there a way to send these images to a database.? Otherwise, am moving to the next module, and that is the one for creating, updating and deleting posts, Pure fun
Hi Corey, not sure if you're still reading these comments. Loving the tutorials. Am up to the end of this video. Pillow is installed for PIP. Run the code and I get the following error. website_1 | File "/logrr/logrr/blueprints/login/views.py", line 74, in accountPage website_1 | picture_file = save_picture(form.picture.data) website_1 | File "/logrr/logrr/blueprints/login/views.py", line 57, in save_picture website_1 | i.save(picture_path) website_1 | File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2004, in save website_1 | fp = builtins.open(filename, "w+b") website_1 | FileNotFoundError: [Errno 2] No such file or directory: '/logrr/static/images/profile_pics/757b0bf5ed6b98cb.jpg' I check and sure enough, in the profile_pics folder there is no file. I changed permissions so that all users can access the folder with full access so it can't be that. Line 74 is calling the save function: picture_file = save_picture(form.picture.data) Line 57 is the actual save line in the function: i.save(picture_path) What could be wrong? I'm a little stumped. Thank you
Now I solved. Problem is this: when we delete the first section of the file, we also delete the name of uploading* object. However, we need it. File we download has also hex-like naming. In fact, we need first and second section of life. My solution for this deactivate the random_hex. In this way, I was able to upload it. However, I am not sure, what kind of security issue it can cause. f_first, f_ext = os.path.splitext(form_picture.filename) picture_fn = f_first + f_ext With this, I am able to upload a new picture.
Hello Sir, I have a question for you. You have a great experience with python and flask before creating this playlist, I want to know your approach on this topic. Before creating this project in this playlist, how much time did you take to get this fluency in the flask model? How many projects do you recommend I to create and build to get this kind of fluency. Your answer will motivate me. Great content by the way, I am learning a lot from you. Thank you for your effort on this.
Once again, every video is excellent. Thank you for your effort and offering to rest of us. Few questions: - I am planning to use Google App Engine + Python 3 + Flask. Will this work? - Also, i want to use GCP's datastore and upcoming firestore. Since we are using sqlalchemy, will it work out of box? - do you have similar example of using Firebase's user authentication.
Love these videos, easy to follow and of just the right length. :) Have a question tho... when I upload a .jpg the orientation changes, is it possible to add some code to prevent that?
Really very nice tutorials Corey. Went through all your videos Django, Flask . Thank you. Hope you would reply my question: How you will know that you need that form or anything to imported if it’s by going through documentation how you manage to go through all the content because one page leads to many sub topics? I really wish you could reply or make a video on this . Thank you once again 😊.
I really love your tutorials. This series specially helps me a lot. But man ... i usually play tuts with 1.25 even as non native english speaker .. but you are that fast o0
great video, really helped me understand some cool tricks with flask. Corey, i was wondering if you could give an example of how to remove the image files from the file directory upon updating profile picture. Thanks again
Decided on Part 3 when I noticed all the repeated/copy and pasted code in the register.html, especially after putting in the if errors code I was going to keep it DRY and find a better way. Now after doing the account form as well I have made it really cleanly. In register.html, login.html, account.html in place of ...... I just put {% include 'includes/_form.html' %} Then I made a includes/_form.html: {{ form.hidden_tag() }} {{ form_title }}
There is a problem if we have more than one account in the system. I was having an issue where I was uploading a picture to my profile but it was displaying the same picture uploaded to all users. The problem was that I was passing the variable image_file to the template set to current_user, like this: "image_file = url_for( 'static', filename='img/profile/' + current_user.image_file)" To solve it I added to my route so I could get the user id from the navbar (I had to add a variable "user_id=current_user.id" in my layout.html). I passed the parameter called "user_id" into the "account" function and defined a "user" variable then I used this "user" instead of "current_user" in the "image_file". However, I also had to pass "user_id=current_user.id" back when I redirected the page, like so: layout.html Account routes "@app.route("/account//", methods=["GET", "POST"]) def account(user_id): user = User.query.filter_by(id=user_id).first_or_404() .... ..... return redirect(url_for("account", user_id=current_user.id)) image_file = url_for( 'static', filename='img/profile/' + user.image_file)" In case anyone runs into this problem.
At about 28:22 Corey mentioned that the Secrets module has been used earlier in the series, but I'm totally blanking on that. Can anyone be a bro and let me know which video and rough time that was?
Hello. Thank you for this series, it was helpful. One question though, can you give a clue about how to clean old profile picture when user changes one. What I think to do is to grab user's profile picture's name, look for it in profile_pics directory and, if found, delete it. Besides that, I am thinking of creating a "job" to make this stuff async. What are your thoughts about that?
Since we generate random names for pictures, there should be a possibility that the algorithm will generate the same random name twice, correct?, and by that we could accidently delete the old picture?! Or the algorithms will never generate the same random names until it 'exhausts' every possible value that could be formed using eight characters? Thank you for the great series, please keep uploading high quality videos :) .
There is a "chance", but that chance is very very very small. We could add some code that checks if an image already exists or is in use, but the chance of colliding names is so small I don't think it's worth it. If the website was going to have millions of users uploading millions of pictures then it would probably be worth it to address possible collisions.
Awesome tutorial. I have a doubt regarding the validation. In case I don't have user authentication feature, won't the updating method fail on validation because you can't check if the current field is getting updated or not(due to duplication check).
Well, Thank you ... You are doing very well series , everything is clear and easy to follow... And I have one questiong concerning the image resize ::: What if the ration of a picture uploaded is not 1x1 ... Can we set dynamic size ? (not just 125px to 125px)
Hey Corey, awesome videos mate!! Quick question, why aren't the images saved in the Database with all the other user info, and they are stored inside the app directory?
DUDE! Ive been trying to figure this out myself xD The app seems to never send the image file to the database, instead only the filename is sent. The app loads the image from the local file system, which is a problem when logging in with foreign devices? Am I mistaken?
In 2024, this is still the best Flask tutorial on the Internet due to its comprehensive coverage of topics, clear explanations, and up-to-date practices.
I'm in my final semester of my degree right now! and the first thing I am going to do as soon as I land a job is to support this channel! This series is just AMAZING!
Totally agree!
did you do it?
@@holajuventud3282 good question
@@Jhonzz4838 ;)
@@Jhonzz4838 I did. lol. Still do.
Watching this series 4 years later and I strongly recommend. Learning a lot.
Corey! I have an interview tomorrow wish me luck! If I get this job the first thing I'll do is support you through Patreon with my first salary. You have taught things so efficiently that no professor has ever taught in these semesters for graduation. You're such a kind person for teaching such valuable content with this brilliant quantity without charging a penny!
@Raptr3x yes mate I got the job. Currently working as a Data Engineer. 😊
@@soumyajitdey5720 Nice, congrats! :D
@@soumyajitdey5720 Congratulations!!
@@soumyajitdey5720 What path would you recommend (or did you take) on your way to becoming a data engineer?
Also I'd like to connect with you on LinkedIn or an other social platform.
Thanks!
How r u doing broo
For anyone wanting to delete the previous profile picture while adding a new one, I added this just before the return statement in the save_picture function:
prev_picture = os.path.join(app.root_path, 'static/profile_pics', current_user.image_file)
if os.path.exists(prev_picture):
os.remove(prev_picture)
thank you :)
You also need to check that previous picture wasn't the default one, because it will also be deleted.
@@darynaishchuk5350 yeah i thought also
The code for anyone who wants to delete the previous profile picture (but never delete the default.jpg) while adding a new one, please add the below code block before the return statement inside the save_picture function:
# Code Block Starts
prev_picture = os.path.join(app.root_path, 'static/profile_pics', current_user.image_file)
if os.path.exists(prev_picture) and os.path.basename(prev_picture) != 'default.jpg':
os.remove(prev_picture)
# Code Block Ends
@@heisenburgfreed7591 could just do
and current_user.image_file != 'default.jpg':
either one works. Yours kinda keeps it more consistent with the os.path thing
Thanks OP. Was struggling with this before this comment.
The pacing of these tutorials and your explanations are just incredible! Shared the series with my Python friends :)
Mr. Schafer is like a teaching machine! Always keeps all things in mind and never stutters or says anything unnecessary!
I really love the fact that whenever I run into any error following these amazing tutorials, the error has been asked and answered in the comments :)
Fantastic series, Corey. Pacing, content, thoroughness, and execution is just great. Thank you for the quality content!
Can anyone clarify if the profile picture is being fetched from the server or from the local filesystem (when GET request is called on the account page)? To me it seems like while the file name is sent to the SQL database, the actual image isn't being sent to the database at all?
@@xtrzne A little late, but I'll answer for those who wonder. After a picture is selected from a local file system on the webpage, it's being put (its resized copy) onto the local filesystem *by the server* (which is now being run locally) into *static/profile_pics* directory. Only the filename goes into the database. It's often a bad thing to store bitmaps in the database as blobs.
loving this tutorial!
i added the code to delete the old profile pic when updating with a new one. this is the if statement in the account function in routes.py
```
if form.picture.data:
old_pic = current_user.image_file
picture_file = save_picture(form.picture.data)
current_user.image_file = picture_file
if old_pic != 'default.jpg':
os.remove(os.path.join(app.root_path, 'static/profile_pics', old_pic))
```
thanks, just what i needed
thank you !
Thank you for the best content when it comes to python and Flask tutorials.
I tried to learn Flask a little too early in my programming journey and when i was stuck i started to search for another tutorial instead of improving my skills.
I came back crawling to you Corey QUICK.
Thank you!
Seriously been searching for days for a complete flask webapp build tutorial. This and from sentdex were the BEST!
This is has become on of the best code tutorials I've ever watched on RUclips!
Thanks!
I like how you started referencing where we set the variable in the past, helps keep track of structure better
I have no experience using any backend framework, except some basic django...
I did not expect such an amazing quality from a RUclips tutorial, which is free!
thankyou!
this is an amazing series!
you're god sent for broke students!
Hello, my name is Pedro and I live in São Paulo, I am writing this text to thank you immensely because you are not only helping me in my professional life but also in my academic life. Keep being this amazing person that you are and may there be others like you over the years, thank you very much.
Duuuuuuuuuuuude, you're a beeeaaaaaaaaaast !
Your tutorials are awesome ! keep the good work !
If you could put a series about Laravel that would be dope !
You got some high quality skills in teaching !
Thanks a lot !
Thanks!
Corey, Your python videos are really amazing. I started python programming after a decade and I'm into it now. But my job is mostly in automation testing. Wanted to change to development and picked your series. Can't stop in btw, yesterday I started and now I'm in part 7. With this video reference, I can able to build the website. Amazing Work!!
One of the best tutorials on anything i've ever watched
nice pfp
Another LEGENDARY vid!
When I saw you install Pillow, I thought to myself "Python is like the car, and these extensions are like aftermarket parts... " :)
This tutorial is way better than some of the payed courses online. Thank you. This is excellent...
I am glad I make typos i.e. pictures instead of picture. Helps me understand when I troubleshoot issues. Thank you,
Corey, I can't thank you enough for this series. Amazing work..
In order to make the picture upload work on the current version of Python and Flask, in "forms.py" I had to change:
[code]
picture = FileField('Update profile picture', validators=[FileAllowed('jpg', 'png')])
[/code]
to:
[code]
picture = FileField('image', validators=[FileRequired(), FileAllowed(['jpg', 'png'], 'Images only!')])
[/code]
Last but not least, thank you for the great series!
I think you only had a problem because you forgot to put the file types into a list. [FileAllowed('jpg', 'png')]) should have been [FileAllowed(['jpg', 'png'])]). He had the brackets correct in the video and it worked for me on the newest version. When I was following along I wasnt expecting to have to use the list, so I'm guessing you thought the same and didn't notice him do it.
@@h82fail I see what I did wrong now. Thanks for pointing it out!
If you want to prevent avatars from stretching, add object-fit:cover; to the .account-img class in main.css
every bit i m developing while seeing your videos making me so happy and the reason is you.
Thank you so much for amazing video...God bless you.
These are sensational tutorials Corey, thanks and please expand on the features!
corey schafer is forever a legend!
This is even better than the CS50 Webapp tutorials at Uni!
A video of master Corey just make my day like nothing
even on these longer vids, the pacing is spot on. subscribed
I've never felt dumber and smarter while watching a video. I guess that's still progress. Thank you
I WONDER !!!!!
how much practice it takes to teach like this
💯 helpful
GREAT,THANK YOU.
Dude your dog is so cute omg
tbh, this is the best flask tutttoriallll for beginnerr.....
What a cute photo of your dog! Looks like a good boy.
For the profile picture @21:57 , I had to change
picture = FileField( 'Update Profile Picture', validators= [ FileAllowed ( [ 'jpg', 'png' ] ) ] )
to
picture = FileField( 'Update Profile Picture', validators=[ FileRequired(), FileAllowed ( [ 'jpg', 'png' ] ) ] )
and also
import FileRequired
at the starting of the file.
maybe because I'm using Python3.5 and not 3.6
Thanks for the awesome tutorials @CoreySchafer
thanks, brother!
I am a teen. As soon as I land a settled job, I am gonna support this channel
Remember This Comment
@@photon6156 cool, see you here after 6 years
yo i am here, 3 years before time
i have the money now
i just turned 18 like 10 days ago, im gonna get my paypal and support this guy
I guarantee you'd be a millionaire if these were paid courses. thankyou for providing this godlike content for absolutely free!
as a zero knowledge person about coding, i wonder how did I able to go this far in the series(Part 8) and be able to successfully roll out the apps. Thank you for these videos. I am very excited finishing this apps.
I fell in love with Flask because of you :)
This videos are amazing and complete, support this channel is a must!
Just a question for the audience, to see if someone is having the same problem:
- On the account route, when updating the current_user.name and current_user.email with the form data, then doing the db.session.commit() is not updating the DB but the commit returns None as if everything was Ok, has somebody run into the same problem??
Thank you very much again!
I have the same problem. Have you found the solution for this?
same
Quality content continues. Respect from Pakistan!
Just fyi, this video used
picture_path = os.path.join(app.root_path + "static/profile_pics" + picture_fn)
Corey is using mac, and it works for him, but for people using windows please use:
picture_path = os.path.join(app.root_path + r"\static\profile_pics\\" + picture_fn)
Thanks for catching that! I think the best solution is to simply pass in static and profile_pics as different arguments like so...
picture_path = os.path.join(app.root_path, "static", "profile_pics", picture_fn)
I will issue a correction in the next video I add to this series. Thanks again!
Yup, join should take care of that.
Thanks for these tutorials Corey. Really appreciate em.
I am not as fast as the other guys, who finished these tutorials in a day or two. I am on week two. :)
Hey just coming here after 3y to thank you alot, lifesaver comment
29:00 - Even though the likelihood of two 8-byte numbers being the same is astronomical, might as well check to make sure the image doesn't already exist and if so, regenerate a new hex.
Ha! When I got to that part I thought the same thing and immediately checked the comments to see if anyone else did too... Agree that it's incredibly unlikely, but better safe than sorry.
How would you do this? Query the DB , right just like earlier with usernames and emails?
@@BtheDUB Actually you would probably have to check the profile_pics folder with the os.listdir() function and compare them to generated hex. If the file already exists, regenerate new hex. But as been told, that's not very likely.
damn this tutorial series really has it all.
Great series Corey! Can't thank you enough.
Realy impressive tutorials with legendary explanations. Thanks !!!
You are the best thing that has ever happened to me! I thank you very much. Thank you for existing!
Guess how many times I came back to this series
Love the Flask-Series!! Keep it up
Wow, thank you for these great videos! I mostly program as a hobby, and have had trouble finding good resources on web development, and was honestly quite intimidated, but you, as always, provide a great series!
I have a question about the render_template() function: what determines whether or not you need to pass a variable to it? For example, `title` and `image_file` are passed in, but current_user isn’t, but still works fine in the template.
Thank you again!
These are all optional parameters and are autoscaled into the function as context variables. The only required parameter is the resource template which is our actual html. The rest can be left out and can be either made use of or ignored. render template is coded to be as flexible as possible hence the use of autoscaping here (**). Its why that one function works for, taking in as many parameters as needed without needing restructuring of the function.
For those wondering how to remove the previous image from the profile_pics directory after updating the profile picture. It's just as simple as adding this line in the save_picture() function:
- if current_user.image_file != 'default.jpg:
os.remove(os.path.join(app.root_path,
'static/profile_pics', current_user.image_file))
It has be added before this line:
- i.save(picture_path)
Let me know if someone find another solution!
this series is EPIC
Hey man great job on the whole flask playlist
Thanks!
i love your series, very helpful, very clearly, thanks so much
Love from Bangladesh, You're so amazing...thanks Corey Schafer.
great tutorial, but the puppy is amazing!!!
Haha thanks
That doggo is real cute!
Would be super interesting to add how to auth with GMail, for instance.
This series is awesome, thank you so much! Subbed!!
While your puppy picture was on I heard nothing you said :D In my mind only "AAAWWWWWW, CUUUUTTTEEE"!
Thank you from Armenia,m you are amazing!!!
Great tutorial series! Thanks so much!
Hi Corey, Excellent video, this was extremely helpful! Can you add a quick video to show us how we can add pictures and video files to each post? I would like the user to have the ability to include photos from their desktop and add to their posts. I love that they can add photos to their profile and would like to provide the option for them to include photos within their posts as well. Thanks so much!!
Something that I noticed is Emails are NOT case sensitive and that should be taken into account when making a website that requires email or else people can sign up for multiple account using same email by changing capitalization their email.
I really love the series and am really having fun, I just have one question on this module though...I thought we will be sending the images the users upload to the database, why are we sending them to the static folder? Is this how real world web apps work, or is there a way to send these images to a database.?
Otherwise, am moving to the next module, and that is the one for creating, updating and deleting posts, Pure fun
very nice Corey !
Your videos are magical
Amazing tutorial.. thank you for your efforts
Hi Corey, not sure if you're still reading these comments. Loving the tutorials. Am up to the end of this video. Pillow is installed for PIP. Run the code and I get the following error.
website_1 | File "/logrr/logrr/blueprints/login/views.py", line 74, in accountPage
website_1 | picture_file = save_picture(form.picture.data)
website_1 | File "/logrr/logrr/blueprints/login/views.py", line 57, in save_picture
website_1 | i.save(picture_path)
website_1 | File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2004, in save
website_1 | fp = builtins.open(filename, "w+b")
website_1 | FileNotFoundError: [Errno 2] No such file or directory: '/logrr/static/images/profile_pics/757b0bf5ed6b98cb.jpg'
I check and sure enough, in the profile_pics folder there is no file. I changed permissions so that all users can access the folder with full access so it can't be that.
Line 74 is calling the save function:
picture_file = save_picture(form.picture.data)
Line 57 is the actual save line in the function:
i.save(picture_path)
What could be wrong? I'm a little stumped. Thank you
Hey, I know time passed but it worths to ask. I have same problem and tried same things. Have you found any solution?
Now I solved. Problem is this: when we delete the first section of the file, we also delete the name of uploading* object. However, we need it. File we download has also hex-like naming. In fact, we need first and second section of life. My solution for this deactivate the random_hex. In this way, I was able to upload it. However, I am not sure, what kind of security issue it can cause.
f_first, f_ext = os.path.splitext(form_picture.filename)
picture_fn = f_first + f_ext
With this, I am able to upload a new picture.
Hello Sir,
I have a question for you. You have a great experience with python and flask before creating this playlist, I want to know your approach on this topic. Before creating this project in this playlist, how much time did you take to get this fluency in the flask model? How many projects do you recommend I to create and build to get this kind of fluency. Your answer will motivate me.
Great content by the way, I am learning a lot from you. Thank you for your effort on this.
Once again, every video is excellent. Thank you for your effort and offering to rest of us. Few questions:
- I am planning to use Google App Engine + Python 3 + Flask. Will this work?
- Also, i want to use GCP's datastore and upcoming firestore. Since we are using sqlalchemy, will it work out of box?
- do you have similar example of using Firebase's user authentication.
superb tutorial! thank you very much man.
Love these videos, easy to follow and of just the right length. :) Have a question tho... when I upload a .jpg the orientation changes, is it possible to add some code to prevent that?
Really very nice tutorials Corey. Went through all your videos Django, Flask . Thank you. Hope you would reply my question:
How you will know that you need that form or anything to imported if it’s by going through documentation how you manage to go through all the content because one page leads to many sub topics? I really wish you could reply or make a video on this . Thank you once
again 😊.
Your dog is lovely!
Thank you! Incredible content, loved it
impressive and analogical.....
I really love your tutorials. This series specially helps me a lot. But man ... i usually play tuts with 1.25 even as non native english speaker .. but you are that fast o0
great video, really helped me understand some cool tricks with flask. Corey, i was wondering if you could give an example of how to remove the image files from the file directory upon updating profile picture. Thanks again
thank you so much sir you are the best i think this channel is the best , really great content
great work, amazing help.
Talented Corey Thanku
This Videos Really make Programming easy. Thanks Corey for the great content. Do you have a Link of the Django version of this content
Decided on Part 3 when I noticed all the repeated/copy and pasted code in the register.html, especially after putting in the if errors code I was going to keep it DRY and find a better way. Now after doing the account form as well I have made it really cleanly.
In register.html, login.html, account.html in place of ...... I just put {% include 'includes/_form.html' %}
Then I made a includes/_form.html:
{{ form.hidden_tag() }}
{{ form_title }}
Great videos! Thank you very much!
@13:35, we can use `ctrl+shift+;` to delete the html tag in sublime
There is a problem if we have more than one account in the system.
I was having an issue where I was uploading a picture to my profile but it was displaying the same picture uploaded to all users. The problem was that I was passing the variable image_file to the template set to current_user, like this:
"image_file = url_for(
'static', filename='img/profile/' + current_user.image_file)"
To solve it I added to my route so I could get the user id from the navbar (I had to add a variable "user_id=current_user.id" in my layout.html). I passed the parameter called "user_id" into the "account" function and defined a "user" variable then I used this "user" instead of "current_user" in the "image_file". However, I also had to pass "user_id=current_user.id" back when I redirected the page, like so:
layout.html
Account
routes
"@app.route("/account//", methods=["GET", "POST"])
def account(user_id):
user = User.query.filter_by(id=user_id).first_or_404()
....
.....
return redirect(url_for("account", user_id=current_user.id))
image_file = url_for(
'static', filename='img/profile/' + user.image_file)"
In case anyone runs into this problem.
your puppy is beautiful
At about 28:22 Corey mentioned that the Secrets module has been used earlier in the series, but I'm totally blanking on that. Can anyone be a bro and let me know which video and rough time that was?
It was in Part 3 at about 11:00 minutes. We used it to generate a random string of characters for our secret key.
I did exactly what you did on tutorial but even after uploading the picture it doesn't appear on the account page
Hello. Thank you for this series, it was helpful. One question though, can you give a clue about how to clean old profile picture when user changes one. What I think to do is to grab user's profile picture's name, look for it in profile_pics directory and, if found, delete it. Besides that, I am thinking of creating a "job" to make this stuff async. What are your thoughts about that?
Since we generate random names for pictures, there should be a possibility that the algorithm will generate the same random name twice, correct?, and by that we could accidently delete the old picture?!
Or the algorithms will never generate the same random names until it 'exhausts' every possible value that could be formed using eight characters?
Thank you for the great series, please keep uploading high quality videos :) .
There is a "chance", but that chance is very very very small. We could add some code that checks if an image already exists or is in use, but the chance of colliding names is so small I don't think it's worth it. If the website was going to have millions of users uploading millions of pictures then it would probably be worth it to address possible collisions.
Thank you for the explanation :) .
Awesome tutorial. I have a doubt regarding the validation. In case I don't have user authentication feature, won't the updating method fail on validation because you can't check if the current field is getting updated or not(due to duplication check).
Well, Thank you ... You are doing very well series , everything is clear and easy to follow... And I have one questiong concerning the image resize ::: What if the ration of a picture uploaded is not 1x1 ... Can we set dynamic size ? (not just 125px to 125px)
38:09
Amazing. Thank you so much!
Hey Corey, awesome videos mate!! Quick question, why aren't the images saved in the Database with all the other user info, and they are stored inside the app directory?
DUDE! Ive been trying to figure this out myself xD The app seems to never send the image file to the database, instead only the filename is sent. The app loads the image from the local file system, which is a problem when logging in with foreign devices? Am I mistaken?
It's cooler than the series from Game of Thrones
Thank you