I have a long-term university-paid subscription to Lynda and have spent many, many hours there learning code. It's a great service, and I love it, BUT THIS VIDEO SERIES IS BETTER than any series on Django I've found there!!!! You have filled in a number of "blanks" left by other tutorials and I feel much more confident that I actually understand the framework now.
You are legitimately the best teacher I've seen on RUclips. With other tutorials here on RUclips I follow along but feel like I don't actually learn much. But with your explanations it's easy for me to follow along and apply the knowledge into my own projects!
I'm a student in Ghana(West Africa). I don't have the means to contribute to the patreon....but surely, I'm going to make so many others wanting to learn python and Django/flask hear of you. I'm so grateful for the impact you're having on me.
i found that putting the picture of who displayed the comment looks much nicer, so in the home.html right above the post.author if we add the line the post section looks a bit nicer, i am new at this but thanks to Corey i was able to understand some concepts.
I've been looking for a sensible explanation for this bit for roughly 4 months now, and I just wanted to express my absolute awe. Absolutely professional, handy with the ol' typewriter, no rubbish code and moreover no rubbish small talk. You sir, are a God among ants within the django tutorials realm, hands down. An instant subscription was made, obviously. Thank you ever so much for taking the time to make these videos ^_^
You are the best ! I am in a coding boot camp and I feel your videos are much better than boot camp! Will pass on money as soon as I start making some !
This tutorial is the best tutorial i hve seen so far. its the best. paid contents dont even have the explanations. I will donate when i land my first job as a django dev. thanks a ton corey
For those not getting a profile pic to load around the 25:30 mark, make sure you're putting the default.jpg into the project_name/media folder, and not in the project-name/media/profile_pics folder. I didn't listen to Corey closely enough, but he mentions this specifically, although it seems minorly counterintuitive.
@@Will_CS Had the same problem. Along with urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) try adding to the root urls.py this urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Firstly, Great tutorial Corey! Simply the best! For those of you having issues where the profile isn't saving or the default image isn't showing up, please make sure to tab properly. In the apps.py file in the users directory, please make sure that 'def ready(self):...' isn't on the same column as 'class UserConfig(AppConfig). Tab appropriately. Hopefully, this helps someone. God Bless!
If a profile doesn't get created when you sign up a new user, add: default_app_config = 'users.apps.UsersConfig' to the __init__.py file in the users app. This solved my issue, even when the code was correct and I followed the steps in this video properly.
thankyou Corey, great vid great work! btw, for those struggling on default picture, create a profile for your user (without adding picture), because you need to create profile for the user in order to add default picture to the profile.
@monoj sorry for the late reply. African timezone. My understanding is that that users you created before you created the Profile model do not get a profile, which also means they don't get an image field. Only those users you create after creating the Post model will have the image field apply to them. Furthermore, take care to store that default picture in the right place. I made a mistake there as well. I hope this helps.
Man, I run into some issues like Pillow, and I am like "oh, man, I need to solve it because Corey has it installed". I solve it and then next frame you are showing what to do. Really appreciate your work.
For anyone using Path from pathlib library, and getting an error saying 'os' not defined, please replace the following line from the video: Replace: MEDIA_ROOT = os.path.join(BASE_DIR, 'media') With: MEDIA_ROOT = BASE_DIR.joinpath('media') Also, if it still throws error, please check that you have the following line in your settings.py: BASE_DIR = Path(__file__).resolve().parent.parent If its not there, please add it right after the Path import (where you should find it if it is there) Great tutorials Corey :)
@@fabrzy3784 yes, you can import os library and use the exact same code that is shown in the video.. I'm not using os library, and my comment focuses primarily on using Path library instead of os library.. since when I created a django project recently, os library was not imported by default in my settings.py file..
Excellent Teacher! You make me to love the Django framework more and more! Keep the awesome work Corey. Simple I have to say thank you so much!!!!!!!!!!
you are the best teacher in the world. I have seen many videos and I have learned many things from you. 3:08 we have to specified the related_name='profile'. so the reverse accessor will be called profile not userprofile.
Should incase you have errors implementing the signals, you can do this to your users models.py file def save(self, *args, **kwargs): super(Profile, self).save(*args, **kwargs)
Sorry for the previous question. I discovered that my default image was actually named default.jpg.jpg which did not show up til I went to the command line. Once i renamed it, everything worked fine. Thanks again for these wonderful videos.
If you are having problems with the default image. Ensure you rename whatever picture you're using to default and place that image in the media folder not the profile pics sub folder in the media folder
For those that the profile wasn't created automatically, you must put it [default_app_config = 'users.apps.UsersConfig'] in your users/__init__.py and also check that default.jpg should not inside media directory . But both media and defalt jpg should be in same place.
but am now stuck here - ImportError: cannot import name 'Profile' from 'post2.models' i named my app 'post2' this happened while trying to create ProfileUpdateForm
If you get the UserDoesNotExist error, PLEASE double check your function name. I forgot to rename it and I had 2 create_profile functions. 20 mins of debugging later I found it :)
If anyone feels confused at 30:00 , you can use this: @receiver(post_save, sender=User) def create_profile(sender,instance,created,**kwargs): if created: created_profile=profile(user=instance) created_profile.save()
Your tutorials are damn amazing, I learned so much in such a short time. I have only one question - to avoid confusion wouldn't it be better to create a new User model that would inherit built-in User model? (if that is even compatible with built in auth system)
If you are having this error "Instance of 'OneToOneField' has no 'username' member" in users/models at 'return f'{self.user.username} Profile," here is the solution: 1. pip install pylint-django 2. If you are using vscode, go your .vscode/settings.json and add this snipet with the "python.pythonPath" existing there, separate them with comma: "python.linting.pylintArgs": [ "--load-plugins", "pylint_django" ] -> Or, if you have a .pylintrc file, you can add this line to load the plugin: [MASTER] load-plugins=pylint_django Then you are good to go
Hey, First of all thanks for addressing this issue. I'm working with vscode and having trouble with this, could you please elaborate on this a little more? I found the python path in settings but the field simply says python, That's it. Should I copy this whole snippet there?
@@kshitijchourey441 Got to this link, I explain better there. If it works for u, support me there, by leaving a comment. And if you are still having a problem with it, let me know. stackoverflow.com/questions/55204906/instance-of-onetoonefield-has-no-username-member/62771766#62771766
re: signals (31:10)... Corey: "I hope that makes sense..." Me: "Not even a little." 🤣
5 лет назад
First, thank you for all your videos ! Now i have an observation: when you delete a profile or a user you don't delete the picture attached to it. So I made a signal for this: @receiver(post_delete, sender=Profile) def delete_profile(sender, instance, **kwargs): if instance.image != Profile.image.field.default: os.remove(instance.image.path) it works, but if you see something i should change, I will really appriciate your expertise :)
Fantastic. Ran into a little issue. Maybe you mentioned it an earlier video but to get this section to work you need to add default_app_config = 'users.apps.UsersConfig' to the users/__init__.py
I had a problem that the signal wasn't working after all of that (The profile wasn't being created). What solved to me was: 1 - Adding *post_save.connect(save_profile, sender=User)* at the end of *signals.py* 2 - Adding *default_app_config = 'users.apps.UsersConfig'* into __init__.py , that is on root directory of users's aplication
You do not need save_profile function in the signals.py as the function Profile.objects.create will automatically save the profile. Or am I missing something? Also, like every video of this guy if you have no other way to support.
First of all, thank you so much for your open-source approach and also for making information accessible and free for all. To me, these virtues are very important and admirable. On the other hand, like Einstein said: "If you can't explain it simply, you don't understand it well enough." And as also like Da Vinci said: "Simplicity is the ultimate sophistication." So because of that, i firmly believe that the ultimate success in both education and teaching is to simply teach things like a 5 years old can understand. And i believe that this ability is a very rare and exceptional ability that only a few have. Based on the videos of you I watched, I can confidently claim that I have no doubt that you are especially blessed with this ability. Congrats! If we get to the main point, my current progress is halted because of missing of subtitles in your video. As i have hard of hearing and not being a native-speaker, i rely heavily on subtitles, i just can't understand without them. So can you please add auto-generated subtitles by RUclips to this video? Thanks in advance!
Thank you very much for the class and the series. I have only one complaint: i think the videos are getting less and less conceptual. I see what you're doing, i can be convinced of why you're doing it but the knowledge about how the things work on the background don't scratch the surface. I'll do my homework and read more about those decorators you used, but i hope my input is well received.
He has already made a half hour tutorial on decorators (plus two others), so he does go over it, and at the beginning of the first video he states that he won't be going over basic stuff in detail (he isn't explaining if statements or how function definitions work), because he already has videos on that content and this series is about Django, specifically. tl;dr, if he covered every underlying topic (that he already has videos about) along the way then the series would be at least three times longer.
On my next paycheck, I will contribute to you, I am really enjoying your tutorials. Just for information to other viewers, if you have left the server running whilst saving the models.py file it will tell you (HINT) that you need get Pillow. It also shows other useful typo errors. I also understood the importance of reading the documentation and testing out things.
For those whom profile picture didn't load, name your default jpg image just default instead of default.jpg. Otherwise, the image name becomes default.jpg.jpg. Also make sure you are pasting the image in media folder and not profile_pic folder
I am coming back to learning Django for what is now the 3rd time, and I finally get it haha!! I actually started using your video's to learn Python back in 2018... and now I teach Software Development myself (not Django clearly haha!). Thank you for your content, it has gotten me over many a hurdle in the early days and this series has given me something cool to focus on during the xmas break! You really are an incredible teacher!
in django new version we don't have OS package in settings.py so we need to add IMPORT OS at beginning of the settings.py file.. in corey's style SAVE THAT!!!!!!!
tnx to your videos ,those were my first step in django , i am glad that i found your playlist first.....i came now to refer about image field again😁 31:26 i found that we can use PROFILE_OBJECT,CREATED=profile.objects.get_or_create(user=request.user) in views.py we can pass it as instance to form or work it out based on requirement i thought it might help someone i found this after searching for three days
Hey Corey. Since you are using a mac, you can go to system preferences>accessibility>zoom and select "use scroll gesture" and it will allow you to zoom on any part of your screen" (aka the file structure in vs code)
Yes, the signals are a difficult concept to grasp. I am always needing to look at the documentation any time I do signals work as well, so you’re not alone
@@coreyms I wanted to ask that when save_profile method was created in that we write instance.profile.save() but what is 'profile' in this because the class inside the models.py was Profile and not profile so how does it work? Is there any inbuilt variable profile just like user?
In models.py we defined one to one relationship of "user]" with User Class. and post that we defined function based views "profile " in views.py . which we are returning request to profile.html. and "user" is a keyword from django for logged in user. So we can access" profile" through user.profile.
It was an amazing tutorial. Just want to suggest rather than righting the whole pile of code for just setting the default pic, you could have simply checked using this {% if user.profilepic.image %}
@@al3ezi Hi, Actually my code is a little different but can do this code above where you are showing your user actual Pic.Like- {% if not user.profilepic.image %}
And if you want to go by his method just add this line in your 'init.py' file of your app name. In this tutorial the app name was 'blog', so add this line in the init.py file of the blog app- default_app_config = 'blog.apps.blogConfig' .I think by mistake he forgot to tell
i feel like it has something to do with "users/views.py" where @login_required is needed for save_profile func to work. Not really sure if this is right tho but let me know if you find out the exact reason
This seems to be a Django convention to do with OnetoOne model relationships. In this case, we have a 'Profile' class in our models.py with a OnetoOne relationship to user defined as: user = OnetoOne(User, ...). I don't know the correct terminology here but this is my understanding of it: when we have a view (or in this case a signals.py) where we have direct access to a 'Profile' instance, we can get it's user by doing instance.user.whatever_attribute However, when we try to do this in the opposite direction (i.e. we have access to a 'User' instance and we want the users 'Profile') we do instance.profile.whatever_attribute with the lowercase 'p' in question. When you define a OnetoOne (or any model relationship like FK) relationship, it is obviously only defined within one of the models. In this case, we explicitly define the relationship within the 'Profile' model. I think when we do this, Django does some magic under the hood where it creates the relationship in the opposite direction, i.e. it does the equivalent of profile = OnetoOne (Profile, ...) within the 'User' model. When it does this, it seems to simply take the lowercase of the name of the related model, in this case 'Profile'. Not a satisfactory answer, I know, but Django seems to do a lot of things like this. Another example is when you create a new app in your project. The app config name that you include in your project settings.py is automatically generated by Django in the apps.py, so for an app named 'profile', Django will generate a 'ProfileConfig' class in the app's apps.py file. EDIT: The answer is here docs.djangoproject.com/en/3.0/topics/db/queries/#additional-methods-to-handle-related-objects "If a model has a ForeignKey, instances of the foreign-key model will have access to a Manager that returns all instances of the first model. By default, this Manager is named FOO_set, where FOO is the source model name, lowercased. This Manager returns QuerySets, which can be filtered and manipulated as described in the “Retrieving objects” section above."
@@huboy2004 I have found the answer here: docs.djangoproject.com/en/3.0/topics/db/queries/#additional-methods-to-handle-related-objects "If a model has a ForeignKey, instances of the foreign-key model will have access to a Manager that returns all instances of the first model. By default, this Manager is named FOO_set, where FOO is the source model name, lowercased. This Manager returns QuerySets, which can be filtered and manipulated as described in the “Retrieving objects” section above."
@@erickssonnastor5359 I have found the answer here: docs.djangoproject.com/en/3.0/topics/db/queries/#additional-methods-to-handle-related-objects "If a model has a ForeignKey, instances of the foreign-key model will have access to a Manager that returns all instances of the first model. By default, this Manager is named FOO_set, where FOO is the source model name, lowercased. This Manager returns QuerySets, which can be filtered and manipulated as described in the “Retrieving objects” section above."
Nice and neat video as always, Corey. I have a question: why wouldn't we add image profile as a new field to the User model that already exists, but instead create a whole new Profile model and then link to User in 1-1 relation? In other words, when do we know we should create a new entity in the database or just add new attribute to an existing entity?
I got problem at this tutorial. Django said "django.db.utils.OperationalError: no such column: users_profile.user_id". I already checked my code and compared with your code at github and then I found no mistakes. Can you help me to fix it? Your answer will be useful sir. Thankyou
@@jjmovies867 or...change the name in models.py image = models.ImageField(default='default_user.jpg', upload_to='profile_pics') default=anythingyouwant.png, ...
It may be too late: But I just renamed the db.sqlite3 file, deleted the 0001 file in users app, then --> makemigrations --> migrate. You have to also createsuperuser again
24:20 If anyone having trouble with the profile image covering a large part of the screen or the entire screen, you can edit the template 'profile.html' to specify the height and width of the profile image like the following line:
if u won't save it, then it will just create the profile for once and next time when you will try to login again it won't exist anymore, that's why we need to save it at the back end. If there is still some confusion, then we should try out the code without defining save_profile function and see.
@@williamxtc8054 Regarding the ELSE suggestion, that won't make any sense because that would mean either create the profile or save it, do you think this is what we want when we login to any site :)
As far as I understand we use built-in User Model to make a table in the db for users and separately table for objects of Profile. They are connected with OneToOne relationsips. At the end of the video we synchronize creation of a new user and his(her) profile. Benefit - more flexibility as procedure of creation (singing up) is separated from the creation of the profile.
Extending the existing User model¶ There are two ways to extend the default User model without substituting your own model. If the changes you need are purely behavioural and don’t require any change to what is stored in the database, you can create a proxy model based on User. This allows for any of the features offered by proxy models including default ordering, custom managers, or custom model methods. If you wish to store information related to User, you can use a OneToOneField to a model containing the fields for additional information. This one-to-one model is often called a profile model, as it might store non-auth related information about a site user. Ref: docs.djangoproject.com/en/2.1/topics/auth/customizing/
Thank You for helping me, I have one problem when I make new register NewUser3 and after that, I just login in NewUser3 goto profile page I can not view profile default image, I just try your GitHub code, but the same problem is there can you help me
I don't know why, but on Django 2.2 only the last receiver receive the signal, you need to modify the codes to be like this: gist.github.com/saiday/f9e306b0ba5d73d7601ab8e4f3cc65ed
you are facing that issue cause the user you ave used for login does not have profile object present u can create a new user or update the user and create a profile object for the same user. guess you might have found this by the time i have commented. but anyways
Is there a specific reason why we don't implement the ProfilePicture directly in the UserCreationForm we created in ep. 6-User Registration? Thanks a lot for your videos I love this channel!
Dont know why i am getting this error in dev server Not Found: /media/profile_pics/Abdul_Rasid.jpeg [07/Sep/2018 17:54:17] "GET /media/profile_pics/Abdul_Rasid.jpeg HTTP/1.1" 404 3006 and image is also not showing in profile page
Hey, i had the same error. The problem is that i put the settings.DEBUG on the wrong url file. This setting is on the project url file, not on the application url
I love your django series and I am going to watch your other videos as well as soon as i finish. My personal advice for you is to promote your youtube channel on instagram if you want of course. Because people gotta see this masterpiece. Thanks a lot man!
Hi Corey. This is a great tutorial series. Thank you so much for sharing these with us. I have followed all your videos in the Flask series and they have helped me immensely. I was curious though. When you were creating a user profile (automatically after user registration), why did you opt to utilize Django's signals? Couldn't you have just created a profile instance in users/views.py file after form validation and save it? Is there a benefit to using signals?
Hey Corey, I have been working on a small project, and it was developing smoothly until I got a road block which I think this video is the solution for. However, due to the workflow of my website, I am not able to implement exactly the way you are trying to route to the profile page. My workflow is as below 1) user sign up and see a login screen 2) user login and now he see a form, where he/she needs to fill in mandatory fields 3) save and then either click on "profile" page to see the profile data, or "save" button will redirect to the profile page automatically. 4) user logout and the next time he/she logs in should see the profile page directly, and not the form to fill in the extra data. However, after going through your video on "profile" page, I have put the profile in the navbar. So, now even if the user log in to see the form page, he/she still has the profile link to redirect to the profile page through navbar, which is fine. But in the video I didn't see that how you are fetching the data from the data base to show in the "profile" page. May be I didn't understand properly. Sorry if this is a dumb question. I am completely new to web development in general. If you can help me out with the changes in the GET method, I can share my project details to you in google drive, or anyway you want. I have been working on this for some time now, and this is a big road block for me. Please let me know.
I have opened a query on stackoverflow, you could also reply there if you wish stackoverflow.com/questions/61545611/how-to-redirect-to-a-profile-page-and-see-the-data-of-the-logged-in-user-in-djan
Quick heads up for 14:00. os is not imported by default in my case, as BASE_DIR uses pathlib instead of os.
Add the extra line manually:
import os
MEDIA_ROOT = Path(BASE_DIR, 'media')
thanks man
@@abeflor8830 You can also just use slashes.
MEDIA_ROOT = BASE_ROOT / 'media'
docs.python.org/3/library/pathlib.html#operators
Django switched to Pathlib from version 3.
Thanks.
@@abeflor8830 Thanks guys!!
0:22 - profile model, one to one relationship
3:06 - image field
3:47 - __str__ method
4:56 - migration
5:44 - install Pillow
6:36 - add profile to admin page
9:06 - interact with profile on shell
12:41 - setting media root, media url
18:22 - profile template
20:57 - add media route into project url pattern
24:38 - upload default.jpg
26:20 - django signals
32:10 - import signals into ready function of apps.py
I have a long-term university-paid subscription to Lynda and have spent many, many hours there learning code. It's a great service, and I love it, BUT THIS VIDEO SERIES IS BETTER than any series on Django I've found there!!!! You have filled in a number of "blanks" left by other tutorials and I feel much more confident that I actually understand the framework now.
I have had the same experience and feel exactly the same about the paid Udemy courses on Django. We are blessed to have this CH.
You are legitimately the best teacher I've seen on RUclips. With other tutorials here on RUclips I follow along but feel like I don't actually learn much. But with your explanations it's easy for me to follow along and apply the knowledge into my own projects!
I feel the same, we are blessed to have this Ch.
AYYYEEEE MY GOOD SIR
I'm a student in Ghana(West Africa). I don't have the means to contribute to the patreon....but surely, I'm going to make so many others wanting to learn python and Django/flask hear of you.
I'm so grateful for the impact you're having on me.
Thanks!
At first I thought Django was a bit complicated.. Corey made it seem easy and my confidence has grown.
i found that putting the picture of who displayed the comment looks much nicer, so in the home.html right above the post.author if we add the line the post section looks a bit nicer, i am new at this but thanks to Corey i was able to understand some concepts.
That's a very nice touch, thanks
I've been looking for a sensible explanation for this bit for roughly 4 months now, and I just wanted to express my absolute awe.
Absolutely professional, handy with the ol' typewriter, no rubbish code and moreover no rubbish small talk.
You sir, are a God among ants within the django tutorials realm, hands down. An instant subscription was made, obviously.
Thank you ever so much for taking the time to make these videos ^_^
You are the best ! I am in a coding boot camp and I feel your videos are much better than boot camp! Will pass on money as soon as I start making some !
This tutorial is the best tutorial i hve seen so far. its the best. paid contents dont even have the explanations. I will donate when i land my first job as a django dev. thanks a ton corey
Thanks!
Yes. Me too.
I just sent 15€ from paypal for your amazing job. I did few tutorials and yours is so clear.
Thanks again :)
Thanks!
@@coreyms Can you give us auto subtitles pls. It help me a lot :(
For those not getting a profile pic to load around the 25:30 mark, make sure you're putting the default.jpg into the project_name/media folder, and not in the project-name/media/profile_pics folder. I didn't listen to Corey closely enough, but he mentions this specifically, although it seems minorly counterintuitive.
I NEEDED THIS. Thank you for pointing this out.
none of the images are loading, can't figure out why. do you got this issues too?
note: the files are at the correct directories
@@Will_CS Had the same problem. Along with
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
try adding to the root urls.py this
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
@@homosociologicus2000 Thank you for this, I followed this and got my profile pic loaded!
@@homosociologicus2000 thanks for taking the time. Helped me as well :)
Firstly, Great tutorial Corey! Simply the best! For those of you having issues where the profile isn't saving or the default image isn't showing up, please make sure to tab properly. In the apps.py file in the users directory, please make sure that 'def ready(self):...' isn't on the same column as 'class UserConfig(AppConfig). Tab appropriately. Hopefully, this helps someone. God Bless!
Am still having problem of not getting the default images showing after following your suggestion. Will move on to next Part 9. Cant wait to continue.
@@ginisksam hey i am getting the same issue here ? can u help me with this ?
If a profile doesn't get created when you sign up a new user, add:
default_app_config = 'users.apps.UsersConfig'
to the __init__.py file in the users app. This solved my issue, even when the code was correct and I followed the steps in this video properly.
@ProducedByZenith This didn't solve my issue, what else can be done ??
@@sitaramchikkala Not sure mate, just search online with your issue and see what the internet says on how to fix it.
@sitaram chikkala have you gotten a solution ?
thankyou Corey, great vid great work! btw, for those struggling on default picture, create a profile for your user (without adding picture), because you need to create profile for the user in order to add default picture to the profile.
THANK YOU !!!!.. i just gone mad searching for solution XD
Thank you !!
Thank you for this! was getting frustrated
Sorry im going mad for the solution can you explain it briefly? Please @motlasti
@monoj sorry for the late reply. African timezone. My understanding is that that users you created before you created the Profile model do not get a profile, which also means they don't get an image field. Only those users you create after creating the Post model will have the image field apply to them.
Furthermore, take care to store that default picture in the right place. I made a mistake there as well.
I hope this helps.
Man, I run into some issues like Pillow, and I am like "oh, man, I need to solve it because Corey has it installed". I solve it and then next frame you are showing what to do. Really appreciate your work.
Hands down the best teacher I've ever seen! , i wish we had more like you. Thank you for generously sharing you're knowledge 👏👏
I think up to this far, my love for Django is as strong as the tutor....such amazing work. God bless you.
You're really amazing! Even after 1 year and I came back again to relearn and I am able to absorb everything smoothly from you! Thank you Corey!
For anyone using Path from pathlib library, and getting an error saying 'os' not defined, please replace the following line from the video:
Replace: MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
With: MEDIA_ROOT = BASE_DIR.joinpath('media')
Also, if it still throws error, please check that you have the following line in your settings.py:
BASE_DIR = Path(__file__).resolve().parent.parent
If its not there, please add it right after the Path import (where you should find it if it is there)
Great tutorials Corey :)
dont you just have to do "import os" in the settings file ?
@@fabrzy3784 no.. since we are not using the os library, we are using the Path library which should be imported beforehand ^^
@@deepakpatidar8462 but if the error is saying "os not defined" i fixed it with just importing os
@@deepakpatidar8462 also you are using the os library
@@fabrzy3784 yes, you can import os library and use the exact same code that is shown in the video.. I'm not using os library, and my comment focuses primarily on using Path library instead of os library.. since when I created a django project recently, os library was not imported by default in my settings.py file..
Excellent Teacher! You make me to love the Django framework more and more! Keep the awesome work Corey. Simple I have to say thank you so much!!!!!!!!!!
DEFINATELY THE BEST DJANGO TUT I've seen! thanks!
For those having problems with creating a user profile Corey has pinned the solution in the next video.
Thanks for the head up²
There is nothing in the next vedeo
@@منبرالعلوم You need to add your app under installed apps as ''appname.apps.AppnameConfig' if your profile isn't being autocreated!
@@alimamdouh493 thanks a lot.
you are the best teacher in the world. I have seen many videos and I have learned many things from you.
3:08 we have to specified the related_name='profile'. so the reverse accessor will be called profile not userprofile.
Man, I love your videos. You are one a few BEST Teachers on this planet.
Love the comments, I reference this tutorial at least once a year as a refresher... Thanks for your kind work!
Should incase you have errors implementing the signals, you can do this to your users models.py file
def save(self, *args, **kwargs):
super(Profile, self).save(*args, **kwargs)
thanks brother. it worked
@@gauravabhishek3930 glad it did mate
@@brownbread2916 In user model.py we have only Profile model.. are you saying to override profile model save() method
absolute life savor thanks g
Thanks!!
I couldn't have learnt Django without these series. You're a magician Corey.
Just want to give a shoutout to someone very important in my life who inspired me to pursue programming.......
TESTUSER you the man
Sorry for the previous question. I discovered that my default image was actually named default.jpg.jpg which did not show up til I went to the command line. Once i renamed it, everything worked fine. Thanks again for these wonderful videos.
If you are having problems with the default image. Ensure you rename whatever picture you're using to default and place that image in the media folder not the profile pics sub folder in the media folder
thanks corey your making the world a better and smarter place with every tutorial
For those that the profile wasn't created automatically, you must put it [default_app_config = 'users.apps.UsersConfig'] in your users/__init__.py and also check that default.jpg should not inside media directory . But both media and defalt jpg should be in same place.
Thanks!!!
thanks Rahul, i was actually stuck there
but am now stuck here - ImportError: cannot import name 'Profile' from 'post2.models' i named my app 'post2' this happened while trying to create ProfileUpdateForm
Big ups for Corey! He's the best. Thanks alot for this tutorial, even after years of django experience, I'm still coming back to this tutorial!
If you get the UserDoesNotExist error, PLEASE double check your function name. I forgot to rename it and I had 2 create_profile functions. 20 mins of debugging later I found it :)
Having this issue. Still haven’t been able to fix the problem.
@@firstofherkind4136 I am also getting this error
ModuleNotFoundError: No module named 'users.signals'
can u help me?
If anyone feels confused at 30:00 , you can use this:
@receiver(post_save, sender=User)
def create_profile(sender,instance,created,**kwargs):
if created:
created_profile=profile(user=instance)
created_profile.save()
I loved going through your tutorials.
I`m fresh Grad and sure this one of the best series so far to start. Thanks a lot bro
Your tutorials are damn amazing, I learned so much in such a short time.
I have only one question - to avoid confusion wouldn't it be better to create a new User model that would inherit built-in User model? (if that is even compatible with built in auth system)
Cory, I truly cannot thank you enough for your content! Please also consider doing some Q&A as a live stream, that would be great! Thanks again!!!
If you are having this error "Instance of 'OneToOneField' has no 'username' member" in users/models at 'return f'{self.user.username} Profile," here is the solution:
1. pip install pylint-django
2. If you are using vscode, go your .vscode/settings.json and add this snipet with the "python.pythonPath" existing there, separate them with comma:
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django"
]
-> Or, if you have a .pylintrc file, you can add this line to load the plugin:
[MASTER]
load-plugins=pylint_django
Then you are good to go
Hey, First of all thanks for addressing this issue. I'm working with vscode and having trouble with this, could you please elaborate on this a little more? I found the python path in settings but the field simply says python, That's it. Should I copy this whole snippet there?
@@kshitijchourey441 Got to this link, I explain better there. If it works for u, support me there, by leaving a comment. And if you are still having a problem with it, let me know.
stackoverflow.com/questions/55204906/instance-of-onetoonefield-has-no-username-member/62771766#62771766
is your profile page responsive for mobile screen??
@@user-yj7rc2qs8d is your profile page responsive for mobile screen??
@@sarthakbhutani7413 To make your app responsive, you can use Bootstrap class: instead of .
Definitely the most dense tut in this series. Might need to watch this one twice, but it was well layed out. Thanks!
re: signals (31:10)...
Corey: "I hope that makes sense..."
Me: "Not even a little." 🤣
First, thank you for all your videos !
Now i have an observation: when you delete a profile or a user you don't delete the picture attached to it. So I made a signal for this:
@receiver(post_delete, sender=Profile)
def delete_profile(sender, instance, **kwargs):
if instance.image != Profile.image.field.default:
os.remove(instance.image.path)
it works, but if you see something i should change, I will really appriciate your expertise :)
DONE TUTORIAL #8! Thank you SENPAI! :)
BTW im from Philippines 😁
Fantastic. Ran into a little issue. Maybe you mentioned it an earlier video but to get this section to work you need to add
default_app_config = 'users.apps.UsersConfig' to the users/__init__.py
I had a problem that the signal wasn't working after all of that (The profile wasn't being created). What solved to me was:
1 - Adding *post_save.connect(save_profile, sender=User)* at the end of *signals.py*
2 - Adding *default_app_config = 'users.apps.UsersConfig'* into __init__.py , that is on root directory of users's aplication
Corey thanks bro, ur definitely one of the best teachers on planet earth
You do not need save_profile function in the signals.py as the function Profile.objects.create will automatically save the profile. Or am I missing something?
Also, like every video of this guy if you have no other way to support.
Thank you, it helped to fix my error!
I've been watching several videos until I came across this one, and it really helped me a lot! thanks!!
You need to add your app under installed apps as ''appname.apps.AppnameConfig' if your profile isn't being autocreated!
Thanks alot for this
Thanks a bunch for this. Was having challenges with this
ModuleNotFoundError
First of all, thank you so much for your open-source approach and also for making information accessible and free for all. To me, these virtues are very important and admirable.
On the other hand, like Einstein said:
"If you can't explain it simply, you don't understand it well enough."
And as also like Da Vinci said:
"Simplicity is the ultimate sophistication."
So because of that, i firmly believe that the ultimate success in both education and teaching is to simply teach things like a 5 years old can understand. And i believe that this ability is a very rare and exceptional ability that only a few have. Based on the videos of you I watched, I can confidently claim that I have no doubt that you are especially blessed with this ability. Congrats!
If we get to the main point, my current progress is halted because of missing of subtitles in your video. As i have hard of hearing and not being a native-speaker, i rely heavily on subtitles, i just can't understand without them.
So can you please add auto-generated subtitles by RUclips to this video?
Thanks in advance!
Thank you very much for the class and the series. I have only one complaint: i think the videos are getting less and less conceptual. I see what you're doing, i can be convinced of why you're doing it but the knowledge about how the things work on the background don't scratch the surface. I'll do my homework and read more about those decorators you used, but i hope my input is well received.
He has already made a half hour tutorial on decorators (plus two others), so he does go over it, and at the beginning of the first video he states that he won't be going over basic stuff in detail (he isn't explaining if statements or how function definitions work), because he already has videos on that content and this series is about Django, specifically.
tl;dr, if he covered every underlying topic (that he already has videos about) along the way then the series would be at least three times longer.
On my next paycheck, I will contribute to you, I am really enjoying your tutorials. Just for information to other viewers, if you have left the server running whilst saving the models.py file it will tell you (HINT) that you need get Pillow. It also shows other useful typo errors. I also understood the importance of reading the documentation and testing out things.
Thanks!
For those whom profile picture didn't load, name your default jpg image just default instead of default.jpg. Otherwise, the image name becomes default.jpg.jpg.
Also make sure you are pasting the image in media folder and not profile_pic folder
can you help me please
Man, you've been made the best Django tutorials ever. Congrats
THANK YOU SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO MUCH MAN!
I am coming back to learning Django for what is now the 3rd time, and I finally get it haha!! I actually started using your video's to learn Python back in 2018... and now I teach Software Development myself (not Django clearly haha!). Thank you for your content, it has gotten me over many a hurdle in the early days and this series has given me something cool to focus on during the xmas break! You really are an incredible teacher!
in django new version we don't have OS package in settings.py so we need to add IMPORT OS at beginning of the settings.py file.. in corey's style SAVE THAT!!!!!!!
Thank baby jesus I found your comment!
Thanks! This should be pinned!
you dont really have to import the OS package, just use the joinpath like this => BASE_DIR.joinpath('media') 🙂
tnx to your videos ,those were my first step in django , i am glad that i found your playlist first.....i came now to refer about image field again😁
31:26 i found that we can use
PROFILE_OBJECT,CREATED=profile.objects.get_or_create(user=request.user) in views.py
we can pass it as instance to form or work it out based on requirement
i thought it might help someone i found this after searching for three days
The New THENEWBOSTON(bucky roberts)
Hey Corey. Since you are using a mac, you can go to system preferences>accessibility>zoom and select "use scroll gesture" and it will allow you to zoom on any part of your screen" (aka the file structure in vs code)
Thanks! I might try that
this part was kinda confusing for me :/ especially signals part. I find it difficult to use django docs. I hope I will get through this
Yes, the signals are a difficult concept to grasp. I am always needing to look at the documentation any time I do signals work as well, so you’re not alone
@@coreyms I wanted to ask that when save_profile method was created in that we write instance.profile.save() but what is 'profile' in this because the class inside the models.py was Profile and not profile so how does it work? Is there any inbuilt variable profile just like user?
@@direshkumarpradhan4376 did u find the solution...Me also having same issue
The way you explained the signals part was just phenomenal! It was so clear and concise. Thank you so much for this series!
is your profile page responsive for mobile screen??
can you help please
In User class, we never define a class variable called "profile". How can we access user.profile? And why not the capital case user.Profile?
In models.py we defined one to one relationship of "user]" with User Class. and post that we defined function based views "profile " in views.py . which we are returning request to profile.html. and "user" is a keyword from django for logged in user. So we can access" profile" through user.profile.
it is related to user model by one to one relationship so we each user have 1 profile so django model offers us that power
It was an amazing tutorial. Just want to suggest rather than righting the whole pile of code for just setting the default pic, you could have simply checked using this
{% if user.profilepic.image %}
yes please where to add this ?
my default pic not showing !!
@@al3ezi Hi, Actually my code is a little different but can do this code above where you are showing your user actual Pic.Like-
{% if not user.profilepic.image %}
And if you want to go by his method just add this line in your 'init.py' file of your app name. In this tutorial the app name was 'blog', so add this line in the init.py file of the blog app-
default_app_config = 'blog.apps.blogConfig'
.I think by mistake he forgot to tell
at 32:15, why do we do instance.profile.save() ? Where is 'profile' with lowercase 'p' defined?
Did you find out why ??
i feel like it has something to do with "users/views.py" where @login_required is needed for save_profile func to work. Not really sure if this is right tho but let me know if you find out the exact reason
This seems to be a Django convention to do with OnetoOne model relationships. In this case, we have a 'Profile' class in our models.py with a OnetoOne relationship to user defined as: user = OnetoOne(User, ...).
I don't know the correct terminology here but this is my understanding of it: when we have a view (or in this case a signals.py) where we have direct access to a 'Profile' instance, we can get it's user by doing instance.user.whatever_attribute
However, when we try to do this in the opposite direction (i.e. we have access to a 'User' instance and we want the users 'Profile') we do instance.profile.whatever_attribute with the lowercase 'p' in question.
When you define a OnetoOne (or any model relationship like FK) relationship, it is obviously only defined within one of the models. In this case, we explicitly define the relationship within the 'Profile' model. I think when we do this, Django does some magic under the hood where it creates the relationship in the opposite direction, i.e. it does the equivalent of profile = OnetoOne (Profile, ...) within the 'User' model. When it does this, it seems to simply take the lowercase of the name of the related model, in this case 'Profile'.
Not a satisfactory answer, I know, but Django seems to do a lot of things like this. Another example is when you create a new app in your project. The app config name that you include in your project settings.py is automatically generated by Django in the apps.py, so for an app named 'profile', Django will generate a 'ProfileConfig' class in the app's apps.py file.
EDIT: The answer is here docs.djangoproject.com/en/3.0/topics/db/queries/#additional-methods-to-handle-related-objects
"If a model has a ForeignKey, instances of the foreign-key model will have access to a Manager that returns all instances of the first model. By default, this Manager is named FOO_set, where FOO is the source model name, lowercased. This Manager returns QuerySets, which can be filtered and manipulated as described in the “Retrieving objects” section above."
@@huboy2004 I have found the answer here: docs.djangoproject.com/en/3.0/topics/db/queries/#additional-methods-to-handle-related-objects
"If a model has a ForeignKey, instances of the foreign-key model will have access to a Manager that returns all instances of the first model. By default, this Manager is named FOO_set, where FOO is the source model name, lowercased. This Manager returns QuerySets, which can be filtered and manipulated as described in the “Retrieving objects” section above."
@@erickssonnastor5359 I have found the answer here: docs.djangoproject.com/en/3.0/topics/db/queries/#additional-methods-to-handle-related-objects
"If a model has a ForeignKey, instances of the foreign-key model will have access to a Manager that returns all instances of the first model. By default, this Manager is named FOO_set, where FOO is the source model name, lowercased. This Manager returns QuerySets, which can be filtered and manipulated as described in the “Retrieving objects” section above."
Nice and neat video as always, Corey.
I have a question: why wouldn't we add image profile as a new field to the User model that already exists, but instead create a whole new Profile model and then link to User in 1-1 relation? In other words, when do we know we should create a new entity in the database or just add new attribute to an existing entity?
I got problem at this tutorial. Django said "django.db.utils.OperationalError: no such column: users_profile.user_id". I already checked my code and compared with your code at github and then I found no mistakes. Can you help me to fix it?
Your answer will be useful sir. Thankyou
@Indu Ji okay,thank your for the advice. Have a good day!
Indu Ji hey can you help me please??
One of the best tutorial and profile to learning python, very clearly explanation, thanks!
Even though I place the default picture in media folder , djaamgo isn't able to pic that up ..
name that image as default.jpg
Click the link on github to actually see the image then right click and save as. Should fix it
make sure it's not inside the profile pictures subfolder, just put it in the root folder
@@jjmovies867 or...change the name in models.py
image = models.ImageField(default='default_user.jpg', upload_to='profile_pics')
default=anythingyouwant.png, ...
@@Sirreal45 that's a good and better option to do as well
The signals setup works perfect, even with Django's version 3.0.7. Really thanks Master Teacher
is your profile page responsive for mobile screen??
can you help me please??
8:07 I tried to add profile, but I got an Operational error: no such column: users_profile.user_id. Please help.
same problem bro did u sort it out now?
@@shaikirfanameer359 Try running "python manage.py migrate --run-syncdb"
@@stevenpawlowski4873 I tried that too
It may be too late: But I just renamed the db.sqlite3 file, deleted the 0001 file in users app, then --> makemigrations --> migrate. You have to also createsuperuser again
24:20 If anyone having trouble with the profile image covering a large part of the screen or the entire screen, you can edit the template 'profile.html' to specify the height and width of the profile image like the following line:
profile image not loading at all. i will appreciate if you can help me with that
@32:07 why save_profile is required?
doesn't line no 10 serves the purpose?
I also a little bit confused about that part. (That part seems to me should be put into the `else` part of the first function??)
Also, this post does not explain this part either :-)
simpleisbetterthancomplex.com/tutorial/2016/07/28/how-to-create-django-signals.html
if u won't save it, then it will just create the profile for once and next time when you will try to login again it won't exist anymore, that's why we need to save it at the back end. If there is still some confusion, then we should try out the code without defining save_profile function and see.
@@williamxtc8054 Regarding the ELSE suggestion, that won't make any sense because that would mean either create the profile or save it, do you think this is what we want when we login to any site :)
You're just fantabulous 🙏🙏. Words fall small to describe your greatness sir🙏
Why do we create a Profile model instead of extending the actual User? There is any benefit on doing it this way?
As far as I understand we use built-in User Model to make a table in the db for users and separately table for objects of Profile. They are connected with OneToOne relationsips. At the end of the video we synchronize creation of a new user and his(her) profile. Benefit - more flexibility as procedure of creation (singing up) is separated from the creation of the profile.
With the Profile you are extending the User model. Otherwise you have to totally change the User model as a Custom Model.
Extending the existing User model¶
There are two ways to extend the default User model without substituting your own model. If the changes you need are purely behavioural and don’t require any change to what is stored in the database, you can create a proxy model based on User. This allows for any of the features offered by proxy models including default ordering, custom managers, or custom model methods.
If you wish to store information related to User, you can use a OneToOneField to a model containing the fields for additional information. This one-to-one model is often called a profile model, as it might store non-auth related information about a site user.
Ref: docs.djangoproject.com/en/2.1/topics/auth/customizing/
Great work mate! Enjoyed every bit of the tutorials
Why there are no subtitles?
press c on ur system while watching video
perfect content at the perfect speed with the perfect way to teach
Thank You for helping me, I have one problem when I make new register NewUser3 and after that,
I just login in NewUser3 goto profile page I can not view profile default image, I just try your GitHub code, but the same problem is there can you help me
I have this problem too, did you find a solution?
Open the admin page and check if a profile is created for that user or not. If a profile doesn't exist, then the default image will not load!
thanks man
@Evgenii Kosharnyi True Story No worries ✌🏼
@@ishanpadalkar9072 oh my god i spent an hour or so lol thank you!
Amazing Tutorials.Thanks from India .You Rock!!
my image wont load..is there any specific sizes or resolution of image?? tia!
I have the same problem
I found the solution. Change settings.ROOT_URL to settings.MEDIA_URL in urls.py file. It helped me, It was just a little silly mistake. Good luck
I have settings.MEDIA_URL only, but still my image is not loading.
Logout from your admin panel and then login with users credentials with frontend login page
Hey did anyone resolved that error im facing the same problem now
This is better than the course I took on udemy.
this is awesome but if you're looking for another awesome one, I recommend thenewboston's django tutorials
At 16:50, I got "NameError: name 'os' is not defined" solved it by adding the line "import os" at the top of the page
thanks it works for me :)
THANK YOU
Thank you very much for this video tutorial. It is straightforward and absolutely very professional.
When i am creating the user and trying to logged in i am getting RelatedObjectDoesNotExist at /login/ can anyone explain why?
I don't know why, but on Django 2.2 only the last receiver receive the signal, you need to modify the codes to be like this:
gist.github.com/saiday/f9e306b0ba5d73d7601ab8e4f3cc65ed
you are facing that issue cause the user you ave used for login does not have profile object present
u can create a new user or update the user and create a profile object for the same user. guess you might have found this by the time i have commented. but anyways
@@saiday Thanks :)
@@saiday thanks!!! This worked for me!!!
thanks for the video Corey, i would happy if you check why the subtitle is not showing 10s after beginning
I think those who disliked this video were Jamaicans because they read as dis i like
Is there a specific reason why we don't implement the ProfilePicture directly in the UserCreationForm we created in ep. 6-User Registration?
Thanks a lot for your videos I love this channel!
Dont know why i am getting this error in dev server
Not Found: /media/profile_pics/Abdul_Rasid.jpeg
[07/Sep/2018 17:54:17] "GET /media/profile_pics/Abdul_Rasid.jpeg HTTP/1.1" 404 3006
and image is also not showing in profile page
Same problem , help Corey! :P
Not Found: /media/profile_pics/my_pic.jpg
[16/Sep/2018 16:01:00] "GET /media/profile_pics/my_pic.jpg HTTP/1.1" 404 2759
Hi Nehat,
Try to check the static url_pattern you have added, make sure it is using MEDIA_URL and MEDIA_ROOT instead of STATIC.
Thanks
Hey, i had the same error.
The problem is that i put the settings.DEBUG on the wrong url file.
This setting is on the project url file, not on the application url
@@LieviSilva Rename your image as "default.jpg"
@@niteshrawat576 This solved my problem. Thanks!
I love your django series and I am going to watch your other videos as well as soon as i finish. My personal advice for you is to promote your youtube channel on instagram if you want of course. Because people gotta see this masterpiece. Thanks a lot man!
Hi Corey. This is a great tutorial series. Thank you so much for sharing these with us. I have followed all your videos in the Flask series and they have helped me immensely.
I was curious though. When you were creating a user profile (automatically after user registration), why did you opt to utilize Django's signals? Couldn't you have just created a profile instance in users/views.py file after form validation and save it? Is there a benefit to using signals?
Iam getting unique constaint failed error while using signal, can you explain how to create profile using the way you have mentioned?
Hey Corey, I have been working on a small project, and it was developing smoothly until I got a road block which I think this video is the solution for. However, due to the workflow of my website, I am not able to implement exactly the way you are trying to route to the profile page. My workflow is as below
1) user sign up and see a login screen
2) user login and now he see a form, where he/she needs to fill in mandatory fields
3) save and then either click on "profile" page to see the profile data, or "save" button will redirect to the profile page automatically.
4) user logout and the next time he/she logs in should see the profile page directly, and not the form to fill in the extra data.
However, after going through your video on "profile" page, I have put the profile in the navbar. So, now even if the user log in to see the form page, he/she still has the profile link to redirect to the profile page through navbar, which is fine. But in the video I didn't see that how you are fetching the data from the data base to show in the "profile" page. May be I didn't understand properly. Sorry if this is a dumb question. I am completely new to web development in general. If you can help me out with the changes in the GET method, I can share my project details to you in google drive, or anyway you want.
I have been working on this for some time now, and this is a big road block for me. Please let me know.
I have opened a query on stackoverflow, you could also reply there if you wish
stackoverflow.com/questions/61545611/how-to-redirect-to-a-profile-page-and-see-the-data-of-the-logged-in-user-in-djan
So far so good. Great video! Continuing onward...
thank you so much you are one of the best teachers I have ever seen
is your profile page responsive for mobile screen??
Thank you Corey for your time and effort. Keep spreading the knowledge.
this is the best toturial i ve ever seen
The best instructor that ever seen
AMAZING AND CLEAR TUTORIALS WELL DONE COREY!!!