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)
@jstone1cougar6 жыл бұрын
@21:05 files from my photos on my mac were 180 askew so: img.rotate(180)
@anneest6 жыл бұрын
Ah thanks, I got this error and I was going to comment here. Now it works smoothly. Great! :-)
@arfin976 жыл бұрын
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 :)
@varunmahanot57666 жыл бұрын
all of my flash messages are going to the admin page
@Tedraketje5 жыл бұрын
@@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)
@sambegstha12414 жыл бұрын
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.
@ChristopherGeorge19645 жыл бұрын
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!
@ninonazghaidze76875 жыл бұрын
The dog in the picture is the loveliest
@erwinnovo30144 күн бұрын
These videos just keep on getting better and better! Kudos, Corey!
@martianmatt3923 жыл бұрын
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.
@shubhamsirothiya25513 жыл бұрын
My image is not updating
@ebvogt111 Жыл бұрын
@@shubhamsirothiya2551 ensure to be using correct file format (.jpg) and not some random PDF or something.
@sahilbisht36614 жыл бұрын
best teacher ever . dude you explained every little thing so clearly !! love from india
@shashanksharma72424 жыл бұрын
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.
@daphinebabu46143 жыл бұрын
couldn't agree with you more.. corey is incredible!
@nmoore19883 жыл бұрын
Just made the same mistake, thanks for this comment, made me look again.... I mistyped and ended up with 'ecntype'
@zeroXverse5 жыл бұрын
16:40 The Highlight of my morning. Thank you
@vp90415 жыл бұрын
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
@thewordforever48395 жыл бұрын
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
@letsfixedit5722 жыл бұрын
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
@dennischirchir54615 жыл бұрын
You are The G.O.A.T. ...Your explanation is inch-perfect
@ishankamboj35224 жыл бұрын
You are the best teacher for django out there. You teach professionally 👍👍
@theinnoverse4 жыл бұрын
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-up3ks4 жыл бұрын
have u get a programming job?
@theinnoverse4 жыл бұрын
@@ThienNguyen-up3ks nope it's hard in lockdown, I'm looking for a job
@kristiyanpenev18202 жыл бұрын
Mr. Corey, you are simple THE BEST!
@tyler-taewook3 жыл бұрын
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 Жыл бұрын
Thanks bro😂😂😂😂
@TimLin-ui7kp10 ай бұрын
thank you
@adaymunizrosas94864 жыл бұрын
How proud can one be of his dog? I do the same with mine xD
@thetruereality24 жыл бұрын
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.
@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.
@AstronautKanojo8 ай бұрын
You have saved me from failing this class 😭 Subbing for sure, thank you
@JayaPrakash-io2re5 жыл бұрын
Thank you so much Corey Schafer for your Tutorials ....its really really Helping me ..No words to describe it
@pipinstallpython6 жыл бұрын
I'm in love with your coding, thanks for the quality videos so much useful information.
@htfihottopicfeed97343 жыл бұрын
Words can't explain how much i want to thank you for this awsome tutorial
@RebeccaBrunner6 жыл бұрын
Great series so far, thorough but simple.
@banaras.wala.foreignaala4 жыл бұрын
Hi Corey, So far so good, you explained it very well, thanks
@toastrecon5 жыл бұрын
Another great one. Thanks, Corey!
@moebazzi84126 жыл бұрын
AMAZING AND CLEAR TUTORIALS WELL DONE COREY!!!
@friendlychannel1004 жыл бұрын
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 ✌
@pawanchhangani75285 жыл бұрын
You are awesome ❣️ my friend. Love from India
@ksjempire19575 жыл бұрын
You must get a lot of watchtime from these you deserve all those minutes and more
@mr.anderson53934 жыл бұрын
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.
@callmeetc7 ай бұрын
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.anderson53937 ай бұрын
@@callmeetc you cool now?
@AlwarrenSidh5 жыл бұрын
Great video series, I am thoroughly enjoying this.
@mdminhajulislammahin95103 жыл бұрын
Awesome Tutorial Thanks Sir. Take love from Bangladesh
@ΠΑΝΟΣΚΩΣΤΟΠΟΥΛΟΣ-η3χ3 ай бұрын
there is a mistake here i think. the signals interfere with the views and the save method from Profile is called twice when updating the profile(you can check it yourselves by putting a print statement) i fixed by by removing the 2nd signal save_profile as the save method is always being called from the views. also the overrided method needs args and kwargs because the parent function (super) needs them to function.
@Sirreal455 жыл бұрын
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.
@jacobshore5 жыл бұрын
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.
@roba_mutua5 жыл бұрын
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()
@arcadioabrahamherreraabril76063 жыл бұрын
That is an incredible content! Greetings from Spain
@callmeetc7 ай бұрын
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
@kiranraj-dw5gq5 жыл бұрын
Thanks Corey.Awesome Tuts
@bringinglife24 жыл бұрын
This is just excellent! Thanks a lot for the content!
@bowenwang6 жыл бұрын
Too great to stop watching.
@OmarSanchez-ds4qh6 жыл бұрын
started at 11AM and its 4AM now. just too good.
@ronnymokaya6124 Жыл бұрын
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.
@manikndn86 жыл бұрын
Wonderful Corey!
@waqasmushtaq814 жыл бұрын
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)
@hidayathidayat44693 жыл бұрын
can't believe this is free on youtube
@bunchathumbs61943 жыл бұрын
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!
@wladimirovff4 жыл бұрын
Thanks a lot for the course, it's amazing , you are really a good teacher :-D
@bishalgautam38746 жыл бұрын
Great tutor! Keep making such videos
@nickwinnenberg91094 жыл бұрын
That's a really, really cute puppy.
@WajidAli-mf2yk5 жыл бұрын
Hi, Corey, This is an amazing series. I really want to change my tech stack. ( from java to python)
@danielflorez37622 жыл бұрын
Please, dont. Django is so f-ing complicated.
@xvegandersx5 жыл бұрын
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.
@xvegandersx5 жыл бұрын
I should just add that the resizing seems to work, but the logging is still incorrect
@taoufikb5975 жыл бұрын
@@xvegandersx super().save() ?
@lightflix5 жыл бұрын
Hey Corey, your tutorials are great!! The images are not proportional inside the circle so how can we fix that? If I upload an image that's not equal in height and width, it gets stretched. Thank you
@austinpena78595 жыл бұрын
object-fit CSS rule
@ModularPilotJack2 жыл бұрын
If you're watching this in 2022, go profile.html, in the first img class (where profile url is linked) add style="border-radius= 50%" before src="". That will make it a circle :) edit: to make it look less stretched, make sure the HTML class points to the css div account-image
@ildar_eto_ya2 жыл бұрын
Really love it!
@banaras.wala.foreignaala4 жыл бұрын
Oh my god, super().save() this is really super Awesome. So far so good. Thanks
@boryskuczkowski6 жыл бұрын
Hey Corey, after testing the app, I encountered the problem while trying to register new user - save() got an unexpected keyword argument 'force_insert'. I came around it by adding **kwargs into the Profile save function: def save(self, **kwargs): super().save() 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) Is that ok in your opinion?
@mishatet89116 жыл бұрын
That was actually my case. So, thanks for the tip.
@dikdikoobraz28756 жыл бұрын
I had the same problem
@dakshsagar28396 жыл бұрын
Signature of the base method in class Model is save(self, **kwargs) and method overriding it should have the same signature, so adding **kwargs as an argument to save makes sense.
@nasalee37296 жыл бұрын
I have the same issue too, and this solved the problem!!
@azamuray6 жыл бұрын
Thank you
@stasczekalski34365 жыл бұрын
I was having an issue of not seeing authors' profile pictures next to their posts. It turned out the posts were created by users for which I havn't uploaded pictures (and they havn't been uploaded by default, because these users were created before loading default image functionality had been implemented). Be careful not to make the same mistake I did!
@gyappumusoka40165 жыл бұрын
I literally just had the same problem now! I came here to look for answers and here you came. Thanks! I haven't even paid attention to that.
@hasan82675 жыл бұрын
Great tutorials! Thanks
@ingafter63353 жыл бұрын
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
@yongxuanch29304 жыл бұрын
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.
@sripriyar39164 жыл бұрын
Dude thank you very much!! Had a prob with class based update view so had to use Post function in my CBV !
@zebusaqua44152 жыл бұрын
updated save function with delete included. Also does not accidentally delete the default.jpg image def save(self, *args, **kwargs): try: this = Profile.objects.get(id=self.id) if this.image == 'default.jpg': pass elif this.image != self.image: this.image.delete(save=False) except: pass 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)
@triplehaudah4 жыл бұрын
Thanks Corey!
@djudsod9593 жыл бұрын
16:30 the dog is adorable. Instantly Paused the tutorial to mention this.
@PradeepKumar-ps4cs Жыл бұрын
I wasn't able to make crispy forms work my django so I removed crispy tags and all crispy references. On profile page, I can see image, username and email but u_form and p_form (input fields) are not showing up in the browser. Yes, {{ u_form }} and {{ p_form }} are included on profile.html
@PradeepKumar-ps4cs Жыл бұрын
I found the issue, I didnt add context to the render in the last line. After adding ut worked. I compared Corey's code and mone line by line.
@romann_shr Жыл бұрын
VS code is more convenient to me than sublime text since it shows the related functions while typing, so we don't make any typos
@amannegi82563 жыл бұрын
thanku sir for this amazing tutorial series
@amircodes6 жыл бұрын
Thanks Corey.
@patrickouambo10835 жыл бұрын
Thank you sooooooo much for your excellent content on python
@AbhishekKumar-mq1tt6 жыл бұрын
Thank u for this awesome video and series
@Rahul-ut9rd3 жыл бұрын
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
@xintongliu80684 жыл бұрын
1. create update userform and update profile form to the profile page. 2. resize oversize imported ing. 3. add author's img to the post.
@LukaReeson3 жыл бұрын
For anyone how wants to delete the old profile image when you upload a new one: 1. pip install django-cleanup 2. in settings.py INSTALLED_APPS = ( ... 'django_cleanup', # should go after your apps )
@anatoliyloboda46013 ай бұрын
Thank you Corey! But it turns out the small issue. If default imange is updated it is saved into media/profile_pick. So if a user updates their profile multiple times, the old images won't be deleted and the save capacity won't be vacant
@premcharoenpipatsakun785 жыл бұрын
Please keep on making amazing video like this forever >
@stansuen80724 жыл бұрын
Awesome. Thank you.
@niteshpaudel68464 жыл бұрын
That dog is so cute
@jacobyoung57594 жыл бұрын
For those who want to fix the profile page when the invalid/existing username or email appears in the header after a failed profile update: What's happening is that when u_form is checked in is_valid() and fails because of an existing username, the code exits the if block and renders the post request. The problem with that is that the post request.user contains the value for username that failed which is then passed on to the profile template. So to fix this, I retrieved the user of the current session with user = User.objects.get(pk=request.session["_auth_user_id"]) at the top of the function and passed it in as a key, value pair in context, so that context['user'] = user. The template sees the user from context rather than from request then. Also make sure to import from django.contrib.auth.models import User at the top. I'm not sure if this is best practice or not as I am also learning Django with these tutorials, but if anybody has any questions or feedback, feel free to reply.
@jeisaraja98513 жыл бұрын
Thank you so much bro! After hours of trying, i finally found your comment
@hongweisoo2 жыл бұрын
Thank you so much bro! It works and you save my day.
@g3org32104 жыл бұрын
A couple of issues i've got: 1. next to 'Currently: image path/name etc.' i get a tick box that says 'Clear' which if ticked and then submitted will through an error : 'The Profile could not be changed because the data didn't validate.' 2. if i drop a picture in the 'media/profile_pics' and the update with that one would save me another resized picture/file with a suffix type naming on the end instead of overwriting the original just with the new size and keep the naming; i.e if i were to upload the same image over and over i'd get multiple files with a different naming suffixed. Thanks for the course Corey.
@theglammcoder4 жыл бұрын
Same problem whenever i click on clear it shows an image attribute error
@theglammcoder4 жыл бұрын
Same problem whenever i click on clear it shows an image attribute error
@theglammcoder4 жыл бұрын
If you solve it thn plz let me know also.
@SaurabhSharma-gh3rm4 жыл бұрын
Thank you teaching me.
@coreyms4 жыл бұрын
Thanks for learning from me :)
@angjohnsyin95175 жыл бұрын
Kind reminder: after resizing image, gif image will stop animating. If user want to use gif, they can pre-crop it under 300*300 so our system won't crop it
@congcuongnguyen4132 жыл бұрын
0:25 - form to update profile 3:28 - view to update profile 4:54 - template 7:13 - enctype attribute 9:20 - model form 11:11 - pass in POST data 16:41 - auto resize image 23:27 - display author image in post
@sabmost2 жыл бұрын
Pls send the source
@humanOSx5 жыл бұрын
It will be great if you can make a little tutorial show us how to delete old images while saving new in the profile section. Thanks for your awesome work man.
@abdelazizabdelioua8905 жыл бұрын
# Delete Previous Image To Avoid Duplicated Images Of Same User. previous_image = os.path.join(settings.MEDIA_ROOT, request.user.profile.image.name) os.remove(previous_image) I did it you can add this code after checking request method before saving new profile
@humanOSx5 жыл бұрын
@@abdelazizabdelioua890 Thanks.
@SubhashChandra-xy5ke6 жыл бұрын
Awesome article.
@dpapa21754 жыл бұрын
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.
@shashanksharmadon42954 жыл бұрын
Awesome bro thanks best video ever.....
@zacksims36233 жыл бұрын
Great tutorial!
@ranjithak43255 жыл бұрын
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
@tomwojcik6 жыл бұрын
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`.
@junecnol794 жыл бұрын
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
@ahmad-ali145 жыл бұрын
this is the best toturial
@alexanderten54975 жыл бұрын
Your dog is adorable and cute
@676gustavo6 жыл бұрын
you're the man, man!
@ShubhamKumar-gd4sn5 жыл бұрын
Just Awesome man you are great
@jimdanielleencarnacion14413 жыл бұрын
2021 still useful :D
@shubhanshusingh74525 жыл бұрын
You are a lifesaver
@KevinTempelx4 жыл бұрын
Thank you!
@GCKteamKrispy Жыл бұрын
Hey guys. I am very confused on this question: why do we register and update users AND profile? Aren't they same?
@LMGaming04 жыл бұрын
You're amazing dude thanks alot !
@arturofm6 жыл бұрын
around minute 4:40 your speed was like looool jajajaj I had to pause the video like 5 times :D