Тёмный

Python Django Tutorial: Full-Featured Web App Part 9 - Update User Profile 

Corey Schafer
Подписаться 1,3 млн
Просмотров 282 тыс.
50% 1

In this Python Django Tutorial, we will be finishing our user profile page. The final page will allow users to update their information and also add a new profile picture. We will also learn how to resize this image when it is uploaded to save space on our web server. Let's get started...
The code for this series can be found at:
github.com/CoreyMSchafer/code...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python #Django

Опубликовано:

 

25 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 661   
@coreyms
@coreyms 5 лет назад
There is an issue with the code in this video that I fixed in the later videos. If you're getting an error that says something like "save() got an unexpected keyword argument 'force_insert'" then please update the save method in users/models.py to the following: def save(self, *args, **kwargs): super().save(*args, **kwargs)
@jstone1cougar
@jstone1cougar 5 лет назад
@21:05 files from my photos on my mac were 180 askew so: img.rotate(180)
@anneest
@anneest 5 лет назад
Ah thanks, I got this error and I was going to comment here. Now it works smoothly. Great! :-)
@arfin97
@arfin97 5 лет назад
Can you please tell me how do I stop saving duplicate images with new name? If an image I'm uploading is from the same user, it will delete the previous image of the user and save the new one. How can I do that? Btw, thanks for such awesome tutorials :)
@varunmahanot5766
@varunmahanot5766 5 лет назад
all of my flash messages are going to the admin page
@Tedraketje
@Tedraketje 5 лет назад
@@jstone1cougar same problem but then 90degrees to the right. but img.rotate(-90) doesn't seem to do anything. I pasted my code here. if img.height > 500 or img.width > 500: output_size = (500, 500) img.thumbnail(output_size) img.rotate(-90) img.save(self.image.path)
@ninonazghaidze7687
@ninonazghaidze7687 4 года назад
The dog in the picture is the loveliest
@sambegstha1241
@sambegstha1241 4 года назад
That enctype at 6:45 screwed me up real good for 4 days trying to debug the program. I'm glad Corey pointed it out. Thanks Corey.
@ChristopherGeorge1964
@ChristopherGeorge1964 5 лет назад
Been involved in software development for over 30 years and wanting to "build again" on my own and I have to say these tutorials are really awesome!
@sahilbisht3661
@sahilbisht3661 4 года назад
best teacher ever . dude you explained every little thing so clearly !! love from india
@thetruereality2
@thetruereality2 4 года назад
Hi Corey, I have been following your tutorials from the beginning and I understand your explanation quite well. Thank you very much for posting these videos.
@pipinstallpython
@pipinstallpython 5 лет назад
I'm in love with your coding, thanks for the quality videos so much useful information.
@RebeccaBrunner
@RebeccaBrunner 5 лет назад
Great series so far, thorough but simple.
@zeroXverse
@zeroXverse 5 лет назад
16:40 The Highlight of my morning. Thank you
@waqasmushtaq81
@waqasmushtaq81 4 года назад
This is the most useful tutorial I encountered while learning Django. Excellent stuff. 1 small suggestion for the above lesson: Instead of having this twice in views.py: u_form = UserUpdateForm( instance=request.user ) (for GET) u_form = UserUpdateForm( request.POST, instance=request.user ) (for POST) This can be done in 1 line like this: u_form = UserUpdateForm(request.POST or None, instance=request.user)
@ishankamboj3522
@ishankamboj3522 3 года назад
You are the best teacher for django out there. You teach professionally 👍👍
@vp9041
@vp9041 5 лет назад
For blog author image, I just copied the line from users/profile.html and changed the class from account-img to article-img, that too worked. Thanks great explanation
@thewordforever4839
@thewordforever4839 4 года назад
No that doesn't work. It will always show the picture of the user who is logged in, not the actual author of the post
@JayaPrakash-io2re
@JayaPrakash-io2re 4 года назад
Thank you so much Corey Schafer for your Tutorials ....its really really Helping me ..No words to describe it
@AlwarrenSidh
@AlwarrenSidh 5 лет назад
Great video series, I am thoroughly enjoying this.
@toastrecon
@toastrecon 4 года назад
Another great one. Thanks, Corey!
@moebazzi8412
@moebazzi8412 5 лет назад
AMAZING AND CLEAR TUTORIALS WELL DONE COREY!!!
@dennischirchir5461
@dennischirchir5461 4 года назад
You are The G.O.A.T. ...Your explanation is inch-perfect
@letsfixedit572
@letsfixedit572 Год назад
I was trying to make a change to my website. For the last 5 days, I have just wanted to add an image field in my blog, but when I tried to update my Image it won't change today I saw at 7:33 that I want to add an enctype in the form tag. I applied that changes in my HTML file and it works. Thanks a lot, Corey Schefar
@manikndn8
@manikndn8 5 лет назад
Wonderful Corey!
@createlifejr
@createlifejr 4 года назад
This is just excellent! Thanks a lot for the content!
@htfihottopicfeed9734
@htfihottopicfeed9734 3 года назад
Words can't explain how much i want to thank you for this awsome tutorial
@kristiyanpenev1820
@kristiyanpenev1820 Год назад
Mr. Corey, you are simple THE BEST!
@banaras.wala.foreignaala
@banaras.wala.foreignaala 4 года назад
Hi Corey, So far so good, you explained it very well, thanks
@shashanksharma7242
@shashanksharma7242 3 года назад
Corey is so amazing, he anticipates the sections where you could make a mistake. For me I misspelled 'multipart' to mutipart and there was no error but the uploaded image wasn't getting updated. Got back to video and found out he advised about the same trap.
@daphinebabu4614
@daphinebabu4614 3 года назад
couldn't agree with you more.. corey is incredible!
@nmoore1988
@nmoore1988 2 года назад
Just made the same mistake, thanks for this comment, made me look again.... I mistyped and ended up with 'ecntype'
@ksjempire1957
@ksjempire1957 5 лет назад
You must get a lot of watchtime from these you deserve all those minutes and more
@bishalgautam3874
@bishalgautam3874 5 лет назад
Great tutor! Keep making such videos
@friendlychannel100
@friendlychannel100 3 года назад
i am on tutorial 9 and realised i am not a sub yet!... Thank you for this amazing series so far... i went through lots of tutorials but none of them go the ways you do. 💕 will support you when i am able to ✌
@pawanchhangani7528
@pawanchhangani7528 4 года назад
You are awesome ❣️ my friend. Love from India
@martianmatt392
@martianmatt392 3 года назад
This series is incredible, thank you Corey :) I think the enctype thing at 7:35 needs a special emphasis. I spent 30 minutes trying to figure out why the username and email updated fine, but the image wouldn't. Putting this here to hopefully save someone the headache.
@shubhamsirothiya2551
@shubhamsirothiya2551 3 года назад
My image is not updating
@ebvogt111
@ebvogt111 Год назад
@@shubhamsirothiya2551 ensure to be using correct file format (.jpg) and not some random PDF or something.
@kiranraj-dw5gq
@kiranraj-dw5gq 4 года назад
Thanks Corey.Awesome Tuts
@wladimirovff
@wladimirovff 4 года назад
Thanks a lot for the course, it's amazing , you are really a good teacher :-D
@amircodes
@amircodes 5 лет назад
Thanks Corey.
@adaymunizrosas9486
@adaymunizrosas9486 4 года назад
How proud can one be of his dog? I do the same with mine xD
@yehonatan3000
@yehonatan3000 Год назад
Corey, you're a legend, thank you so much! Just a small thing that can help; maybe it will be better if you'll use keyword arguments more often because it helps clarify what is the meaning of every argument we pass. For instance, in the profile function inside the views.py module, we can also write it like this: def profile(request): # u_form = user_form, p_form = profile_form if request.method == 'POST': u_form = UserUpdateForm(data=request.Post, instance=request.user) p_form = ProfileUpdateForm(data=request.Post, files=request.FILES, instance=request.user.profile) else: u_form = UserUpdateForm(instance=request.user) p_form = ProfileUpdateForm(instance=request.user.profile) And then it is much more readable.
@sripriyar3916
@sripriyar3916 3 года назад
Dude thank you very much!! Had a prob with class based update view so had to use Post function in my CBV !
@hasan8267
@hasan8267 5 лет назад
Great tutorials! Thanks
@676gustavo
@676gustavo 5 лет назад
you're the man, man!
@arcadioabrahamherreraabril7606
@arcadioabrahamherreraabril7606 3 года назад
That is an incredible content! Greetings from Spain
@AbhishekKumar-mq1tt
@AbhishekKumar-mq1tt 5 лет назад
Thank u for this awesome video and series
@nickwinnenberg9109
@nickwinnenberg9109 4 года назад
That's a really, really cute puppy.
@monagulapa3022
@monagulapa3022 4 года назад
Thank you for this best tutorial in django. As you mentioned, please also do a video on other ways to resize video that we can use on larger project for efficiency as well as third-party packages.
@triplehaudah
@triplehaudah 4 года назад
Thanks Corey!
@banaras.wala.foreignaala
@banaras.wala.foreignaala 4 года назад
Oh my god, super().save() this is really super Awesome. So far so good. Thanks
@AstronautKanojo
@AstronautKanojo 3 месяца назад
You have saved me from failing this class 😭 Subbing for sure, thank you
@theinnoverse
@theinnoverse 4 года назад
I have completed this part too , really good explanation, now i just have few videos remaining, also i'm coding along, so it's a great experience
@ThienNguyen-up3ks
@ThienNguyen-up3ks 3 года назад
have u get a programming job?
@theinnoverse
@theinnoverse 3 года назад
@@ThienNguyen-up3ks nope it's hard in lockdown, I'm looking for a job
@mdminhajulislammahin9510
@mdminhajulislammahin9510 2 года назад
Awesome Tutorial Thanks Sir. Take love from Bangladesh
@premcharoenpipatsakun78
@premcharoenpipatsakun78 5 лет назад
Please keep on making amazing video like this forever >
@callmeetc
@callmeetc 2 месяца назад
Using this tutorial to catch up with Django for a School Project.. hahaha even with the depricated methods by post date Django 5.0, I still love the learning path and word choice for explanation.. THumBs Up
@SubhashChandra-xy5ke
@SubhashChandra-xy5ke 5 лет назад
Awesome article.
@patrickouambo1083
@patrickouambo1083 4 года назад
Thank you sooooooo much for your excellent content on python
@ShubhamKumar-gd4sn
@ShubhamKumar-gd4sn 5 лет назад
Just Awesome man you are great
@LMGaming0
@LMGaming0 4 года назад
You're amazing dude thanks alot !
@WajidAli-mf2yk
@WajidAli-mf2yk 5 лет назад
Hi, Corey, This is an amazing series. I really want to change my tech stack. ( from java to python)
@danielflorez3762
@danielflorez3762 2 года назад
Please, dont. Django is so f-ing complicated.
@mr.anderson5393
@mr.anderson5393 3 года назад
I have to say thank you very much for the great tutorial. I recreated users app and watched part 6-8 several times, and finally able to do parts 6-8 without watching the tutorial. However, part 6-8 is not a joke- I studied basic OOP, but not like this. Luckly, Mr. Schafer, sir you have explained thigs pretty well for me to understand. Once again great tutorial and thank you very much.
@callmeetc
@callmeetc 2 месяца назад
Hahaha, kept on getting the logour error and got stuck through the very same episodes two day in a row now.... now we off to 9
@mr.anderson5393
@mr.anderson5393 2 месяца назад
@@callmeetc you cool now?
@ildar_eto_ya
@ildar_eto_ya Год назад
Really love it!
@stansuen8072
@stansuen8072 4 года назад
Awesome. Thank you.
@amannegi8256
@amannegi8256 3 года назад
thanku sir for this amazing tutorial series
@tyler-taewook
@tyler-taewook 2 года назад
If your form is working fine but the image isn't being updated, make sure to check you haven't misspelled anything from [enctype="multipart/form-data"] in .html file! I made a typo here which caused the exact same problem, which seems many have also encountered in this comment section
@alimoradi8490
@alimoradi8490 8 месяцев назад
Thanks bro😂😂😂😂
@TimLin-ui7kp
@TimLin-ui7kp 4 месяца назад
thank you
@ahmad-ali14
@ahmad-ali14 5 лет назад
this is the best toturial
@zacksims3623
@zacksims3623 3 года назад
Great tutorial!
@ingafter6335
@ingafter6335 2 года назад
Hi Corey, Many-many thanks for this great and practical tutorials. I have learned a lot from this tutorials. About resizing the image, please advise me to learn more about it. Thanks. Nyoman, from Bali, Indonesia
@shubhanshusingh7452
@shubhanshusingh7452 5 лет назад
You are a lifesaver
@shashanksharmadon4295
@shashanksharmadon4295 4 года назад
Awesome bro thanks best video ever.....
@lardosian
@lardosian 5 лет назад
Hey Corey, would recommend pinning that fix to video 8 as well, many including myself having issues and some of the suggested fixes may not be the best, thanks!
@KevinTempelx
@KevinTempelx 3 года назад
Thank you!
@bowenwang
@bowenwang 5 лет назад
Too great to stop watching.
@OmarSanchez-ds4qh
@OmarSanchez-ds4qh 5 лет назад
started at 11AM and its 4AM now. just too good.
@kartikchauhan5209
@kartikchauhan5209 Год назад
great video
@SaurabhSharma-gh3rm
@SaurabhSharma-gh3rm 4 года назад
Thank you teaching me.
@coreyms
@coreyms 4 года назад
Thanks for learning from me :)
@anoopkg8681
@anoopkg8681 5 лет назад
nice video, thanks
@aidsnyper
@aidsnyper 9 месяцев назад
Thank you very much!
@monagulapa3022
@monagulapa3022 4 года назад
First, I thank you for your kind heart of sharing your knowledge. My question is, how can we delete the old profile picture file, the one that we are going to update. Instead of creating a new file with a suffix added to the filename which is, I noticed, signifies what the latest profile picture is, for the same filename update. What we need is to just delete the old profile picture all throughout. Since for this purpose, it is not that critical for whatever purpose of data rollback or whatever that may be. Please do a video on this too. This is a big help because the effect of this is critical. If not deleted, old, no longer used files, linger on the server which is costly. The way you teach shows your maturity and your experience in the field. I don't mind you teaching the detailed approach, just like what you did in the django deployment in Linux server. I appreciate it so much. We don't have to search for more info. That video alone is enough. If we need more, it's just for some stuff, but the main topic is discussed with full content. Again, I am, and I know most of us who watch your tutorials, are grateful for your effort. Great job Corey !
@bavidlynx3409
@bavidlynx3409 4 года назад
Thank you
@jimdanielleencarnacion1441
@jimdanielleencarnacion1441 3 года назад
2021 still useful :D
@jacobshore
@jacobshore 5 лет назад
Hi, thanks for these videos, they're great! Quick question/clarification: the reason we were able to access the image from the homepage via {{ post.author.profile.image.url }} is because the author column of the post table is a foreign key to the user username table as set in the blog app models + the profile has a one to one relationship with the the user table as set in the user app models - right? It seems kind of intuitive, but I'm looking through the docs to see what would work with this and what wouldn't and I get the sense that in the other frameworks I've experienced (mostly PHP ones like Laravel, Symphony, Yii + Flask) one would have to be much more explicit about these connections - but maybe it's just intuitive b/c you're so smooth and make it seem so obvious. If you, or anyone reading this, could lead me the right documentation, I'd greatly appreciate it.
@KevinTempelx
@KevinTempelx 3 года назад
Thanks!
@alexanderten5497
@alexanderten5497 4 года назад
Your dog is adorable and cute
@bunchathumbs6194
@bunchathumbs6194 2 года назад
If ur watching this course and you are beginner I would recommend you to start with learning Flask first. Yeah Django is amazing but to much stuff if working out of the box. P.S. Tutorial is great!
@yongxuanch2930
@yongxuanch2930 3 года назад
hello there corey, you're videos are amazing, I just want to let you know that after I followed the video my accounts suddenly went wrong so I just want to say that I added this code : def save(self, *args, **kwargs): super(Profile, self).save(*args, **kwargs) img = Image.open(self.image.path) if img.height > 300 or img.width > 300: output_size = (300,300) img.thumbnail(output_size) img.save(self.image.path)' and everything went totally fine.
@egemenguney1715
@egemenguney1715 3 года назад
i've laughed like for 3 - 4 mins for this cute dogo hahahah :)
@ab5848
@ab5848 3 года назад
Thank you sir🙏🙏
@ranjithak4325
@ranjithak4325 4 года назад
Hello Mr.Corey, I really like all your videos, i have a request if you can do a tutorial for reactJS and django application that would be really helpful. Best Regards, R
@xvegandersx
@xvegandersx 5 лет назад
First of all, great tutorials, I've been binge-watching them since this morning. Secondly, I've run into a really weird bug or behavior I do not understand when resizing the images. At first my images wasn't being resized properly so I sprinkled some logging in the save function of the Profile class. Just before the if-statement I logged both img.width as well as self.image.width and the two differed, with the former set to the limit of 300, while the latter had the original size. I then continued to add more logging and added an else statement to make it something like this: needs_resize = img.width > 300 or img.height > 300 logger.error(f'{img.width}x{img.height} {needs_resize}') logger.error(f'{self.image.width}x{self.image.height}') if needs_resize: logger.error("In resize before work") output_size = (300, 300) img.thumbnail(output_size) img.save(self.image.path) logger.error("In resize after work") else: logger.error("No resize needed") The weird thing is that as the above is written, I will get this output: 190x300 False 515x812 No resize needed If I on the other hand comment out the line img.save(self.image.path) I will get this output: 515x812 True 515x812 In resize before work In resize after work Any clue on what's going on? It seems like the img.save function gets called before the if-statement is evaluated somehow.
@xvegandersx
@xvegandersx 5 лет назад
I should just add that the resizing seems to work, but the logging is still incorrect
@taoufikb597
@taoufikb597 4 года назад
@@xvegandersx super().save() ?
@niteshpaudel6846
@niteshpaudel6846 4 года назад
That dog is so cute
@ronnymokaya6124
@ronnymokaya6124 11 месяцев назад
If you're having an issue resizing the image and getting the error Image is not defined, you can try import pillow library "from PIL import Image" and it will work right.
@Sirreal45
@Sirreal45 4 года назад
Corey is great...however, in this video he's using square images to make those perfect circle avatar thumbnails. If you try a non-square image, it will looked kind of skewed. if you want to resize by middle crop to his dimensions. use this... in models.py import an additional Pillow function: From PIL import Image,ImageOps then later in the function def save if img.height > 300 or img.width > 300: output_size = (300, 300) resized = ImageOps.fit(img, output_size, Image.ANTIALIAS) resized.save(self.image.path) this basically crops the image to 300x300 square so that the circle bootstrap and css he provided work.
@robertmutua3267
@robertmutua3267 4 года назад
Great tutorial. In the resizing of the images, how about instead of overwriting the save method, we resize the image before committing the form? Something like: if profile_picture_form.is_valid(): instance = profile_picture_form.save(commit=False) img = Image.open(instance.profile_picture.path) if img.height > 400 or img.width > 400: output_size = (400, 400) img.thumbnail(output_size) img.save(instance.profile_picture.path) instance.save()
@teddytalks499
@teddytalks499 4 года назад
thanks
@zsarx100
@zsarx100 3 года назад
Hi Corey, thanks for this great tutorial. I have followed and created the app, and it's working. How can I add a drop-down list on the profile update form, for the user to choose city of residence ?
@gardenbrazil1959
@gardenbrazil1959 5 лет назад
signals are Great.
@kavabangaungava
@kavabangaungava 5 лет назад
Amazing dog :)
@tomwojcik
@tomwojcik 5 лет назад
19:35 imo you should pass *args **kwargs to both `save` methods. Also, I'm not sure Image closes automatically. I'd use `with open` on that `self.image.path`.
@IterativeTheoryRocks
@IterativeTheoryRocks 4 года назад
Nice Dog.
2 года назад
What a nice dog
@Rahul-ut9rd
@Rahul-ut9rd 3 года назад
We actually don't need to add email field explicitly in UserUpdateForm. As User model already has an email field. We can convert email field from User to model to form field just like username field
@dpapa2175
@dpapa2175 3 года назад
Is to late to ask for additional suggestions about resizing the image? I like what you have, it works, but would be cool to see your other research, too.
@junecnol79
@junecnol79 4 года назад
10:25 ModelForm 기존의 model의 이용하여 form 만들기 docs.djangoproject.com/en/3.0/topics/forms/modelforms/#modelform 11:30 HttpRequest.POST 안에 사용자가 입력한 form data가 들어있다. docs.djangoproject.com/en/3.0/ref/request-response/#django.http.HttpRequest.POST 12:15 HttpRequest.FILES 12:50 multi form validation 17:29 resizing image with pillow 18:25 Model.save() docs.djangoproject.com/en/3.0/ref/models/instances/#saving-objects 24:50 bootstrap rounded-circle article-img
@hidayathidayat4469
@hidayathidayat4469 2 года назад
can't believe this is free on youtube
@AmineOnline
@AmineOnline 3 года назад
THX
@djudsod959
@djudsod959 3 года назад
16:30 the dog is adorable. Instantly Paused the tutorial to mention this.
@arturofm
@arturofm 5 лет назад
around minute 4:40 your speed was like looool jajajaj I had to pause the video like 5 times :D
@coreyms
@coreyms 5 лет назад
Haha. You can set the speed to 0.75 if it helps.
Далее
Повага | GOVOR TikTok #govor #shots
00:53
Просмотров 290 тыс.
NAME THE EURO 2024 PLAYER OR SWIM 💦
00:35
Просмотров 11 млн
Making Minimalist Web Server in C on Linux
10:23
Просмотров 229 тыс.
Django QuickStart Web Application for Beginners
23:11
The ONLY PySpark Tutorial You Will Ever Need.
17:21
Просмотров 121 тыс.
An Illustrated Guide to OAuth and OpenID Connect
16:36
Просмотров 558 тыс.
Elon Musk Isn't Telling Us Something About Neuralink
13:42
Django Login Form and User Authentication
17:01
Просмотров 8 тыс.