title
Python Django Tutorial: Full-Featured Web App Part 8 - User Profile and Picture

description
In this Python Django Tutorial, we will be creating a user profile that extends the built-in Django User model. We will then use this user profile to store profile pictures for each user. We will also be learning how to set the MEDIA_ROOT, MEDIA_URL, and also make our static files accessible through our URL patterns. Finally, we will create a receiver function for a Django signal that will make sure our profiles are created when a user first registers. Let's get started... The code for this series can be found at: https://github.com/CoreyMSchafer/code_snippets/tree/master/Django_Blog Django Static File Docs: https://docs.djangoproject.com/en/2.1/howto/static-files/#serving-files-uploaded-by-a-user-during-development ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Python #Django

detail
{'title': 'Python Django Tutorial: Full-Featured Web App Part 8 - User Profile and Picture', 'heatmap': [{'end': 1400.335, 'start': 1346.439, 'weight': 0.821}, {'end': 1590.258, 'start': 1558.314, 'weight': 0.87}, {'end': 1675.941, 'start': 1626.119, 'weight': 1}, {'end': 1972.565, 'start': 1925.139, 'weight': 0.914}], 'summary': 'Tutorial series on python django covers creating a user profile model, database migrations, pillow library installation, image upload and media settings, profile management, and configuring media urls for user profile setup in django, providing comprehensive guidance on these aspects.', 'chapters': [{'end': 296.282, 'segs': [{'end': 70.911, 'src': 'embed', 'start': 13.166, 'weight': 0, 'content': [{'end': 20.954, 'text': "And we'll also learn how to use Django Signals to run specific functions after certain actions, which can be extremely useful for this type of work.", 'start': 13.166, 'duration': 7.788}, {'end': 22.456, 'text': "So let's go ahead and get started.", 'start': 21.315, 'duration': 1.141}, {'end': 29.683, 'text': "So first of all, by default, the default users model that Django provides for us doesn't have a field for a profile picture.", 'start': 22.756, 'duration': 6.927}, {'end': 31.485, 'text': 'So how can we add that?', 'start': 30.063, 'duration': 1.422}, {'end': 40.993, 'text': "So, in order to do that, we're going to have to extend the user model and create a new profile model that has a one-to-one relationship with the user.", 'start': 31.885, 'duration': 9.108}, {'end': 48.478, 'text': 'so a one-to-one relationship means that one user can have one profile and one profile will be associated with one user.', 'start': 40.993, 'duration': 7.485}, {'end': 52.441, 'text': "so let's go ahead and add this so that our users can have profile pictures.", 'start': 48.478, 'duration': 3.963}, {'end': 60.647, 'text': 'so this will be a new model in our users app, and when we created this app, it created a models.py file for us.', 'start': 52.441, 'duration': 8.206}, {'end': 61.987, 'text': "so let's open that up.", 'start': 60.647, 'duration': 1.34}, {'end': 64.169, 'text': "so I've already got that open up here on my machine.", 'start': 61.987, 'duration': 2.182}, {'end': 68.83, 'text': "So this is the models.py file located inside of your user's app.", 'start': 64.429, 'duration': 4.401}, {'end': 70.911, 'text': 'And we can see that this is currently empty.', 'start': 69.111, 'duration': 1.8}], 'summary': 'Learn to use django signals for running functions after actions, extend user model to add profile picture.', 'duration': 57.745, 'max_score': 13.166, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI13166.jpg'}, {'end': 180.558, 'src': 'embed', 'start': 148.214, 'weight': 4, 'content': [{'end': 151.877, 'text': 'now we saw this in the post model in a previous video.', 'start': 148.214, 'duration': 3.663}, {'end': 153.518, 'text': 'but just a recap.', 'start': 151.877, 'duration': 1.641}, {'end': 158.822, 'text': 'cascade means that if the user is deleted, then also delete the profile.', 'start': 153.518, 'duration': 5.304}, {'end': 161.324, 'text': "but if we delete the profile, then it won't delete the user.", 'start': 158.822, 'duration': 2.502}, {'end': 164.086, 'text': "so it's just a one-way thing and that makes sense.", 'start': 161.324, 'duration': 2.762}, {'end': 167.549, 'text': 'so in this case, if we ever delete a user from a database,', 'start': 164.086, 'duration': 3.463}, {'end': 172.372, 'text': "then there's no reason in keeping around their profile with their images and all that stuff either.", 'start': 167.549, 'duration': 4.823}, {'end': 174.394, 'text': 'so that will just be deleted with the user.', 'start': 172.372, 'duration': 2.022}, {'end': 180.558, 'text': 'Okay, so now that we have a user associated with this profile now we can add any additional fields that we want.', 'start': 174.694, 'duration': 5.864}], 'summary': 'In database, cascade means deleting profile when user is deleted, not vice versa.', 'duration': 32.344, 'max_score': 148.214, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI148214.jpg'}, {'end': 252.748, 'src': 'embed', 'start': 227.953, 'weight': 2, 'content': [{'end': 234.558, 'text': "So now let's create a dunder str method so that when we print this out, it'll display how we want it to be displayed.", 'start': 227.953, 'duration': 6.605}, {'end': 238.52, 'text': "so if you don't know what that is, we talked about it briefly in another video.", 'start': 234.938, 'duration': 3.582}, {'end': 245.804, 'text': "but basically, if we don't have a dunder str method, then anytime we print out a profile, then it's just going to say profile object,", 'start': 238.52, 'duration': 7.284}, {'end': 247.885, 'text': 'and we want it to be more descriptive than that.', 'start': 245.804, 'duration': 2.081}, {'end': 252.748, 'text': 'so if we want it to be more specific, then we need to tell it exactly how we want it to print it out.', 'start': 247.885, 'duration': 4.863}], 'summary': 'Creating a dunder str method for custom printing.', 'duration': 24.795, 'max_score': 227.953, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI227953.jpg'}], 'start': 0.229, 'title': 'User profile model creation', 'summary': 'Discusses extending the user model to add fields for a profile picture, utilizing django signals for specific functions after certain actions, and implementing a one-to-one relationship between the user and profile model. it also introduces creating a user profile model in the users app, extending the existing user model, establishing a one-to-one relationship, adding a profile picture field, and defining a dunder str method for custom display, ultimately impacting the database.', 'chapters': [{'end': 52.441, 'start': 0.229, 'title': 'User profile page enhancement', 'summary': 'Discusses extending the user model to add fields for a profile picture, utilizing django signals for specific functions after certain actions, and implementing a one-to-one relationship between the user and profile model.', 'duration': 52.212, 'highlights': ['Extending the user model to add fields for a profile picture and creating a new profile model with a one-to-one relationship with the user.', 'Utilizing Django Signals for running specific functions after certain actions, which can be highly beneficial for this type of work.']}, {'end': 296.282, 'start': 52.441, 'title': 'Creating user profile model', 'summary': 'Introduces creating a user profile model in the users app, extending the existing user model, establishing a one-to-one relationship, adding a profile picture field, and defining a dunder str method for custom display, ultimately impacting the database.', 'duration': 243.841, 'highlights': ['The chapter introduces creating a user profile model in the users app. It explains the process of creating a new model in the users app and opening the models.py file to work on the profile model.', 'Extending the existing user model and establishing a one-to-one relationship. The chapter elaborates on the process of importing the existing user model from Django and creating a one-to-one relationship with the new profile model.', 'Adding a profile picture field and defining a dunder str method for custom display. It covers the addition of a profile picture field and the creation of a dunder str method to customize the display of the profile object when printed.', 'Impact on the database due to model changes. It emphasizes the impact of any changes to the models on the corresponding database.']}], 'duration': 296.053, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI229.jpg', 'highlights': ['Extending the user model to add fields for a profile picture and creating a new profile model with a one-to-one relationship with the user.', 'Utilizing Django Signals for running specific functions after certain actions, which can be highly beneficial for this type of work.', 'Adding a profile picture field and defining a dunder str method for custom display. It covers the addition of a profile picture field and the creation of a dunder str method to customize the display of the profile object when printed.', 'Extending the existing user model and establishing a one-to-one relationship. The chapter elaborates on the process of importing the existing user model from Django and creating a one-to-one relationship with the new profile model.', 'Impact on the database due to model changes. It emphasizes the impact of any changes to the models on the corresponding database.', 'The chapter introduces creating a user profile model in the users app. It explains the process of creating a new model in the users app and opening the models.py file to work on the profile model.']}, {'end': 692.7, 'segs': [{'end': 326.999, 'src': 'embed', 'start': 296.282, 'weight': 0, 'content': [{'end': 298.164, 'text': "but it hasn't made any changes yet.", 'start': 296.282, 'duration': 1.882}, {'end': 301.706, 'text': 'we still need to run our migrations for those changes to take effect.', 'start': 298.484, 'duration': 3.222}, {'end': 307.088, 'text': "And that's also the great thing about migrations, because we can make database changes like this over time.", 'start': 302.066, 'duration': 5.022}, {'end': 310.29, 'text': "Okay, so let's bring up our terminal and run these migrations.", 'start': 307.349, 'duration': 2.941}, {'end': 317.614, 'text': "So I'm going to bring up my terminal here, and I'm currently in my project directory where my manage.py file is located.", 'start': 310.31, 'duration': 7.304}, {'end': 326.999, 'text': 'So remember, we can create migrations for our changes just by saying python manage.py make migrations.', 'start': 318.074, 'duration': 8.925}], 'summary': 'Database changes can be made over time using migrations; run migrations for changes to take effect.', 'duration': 30.717, 'max_score': 296.282, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI296282.jpg'}, {'end': 365.515, 'src': 'embed', 'start': 338.442, 'weight': 1, 'content': [{'end': 343.944, 'text': 'And then it gives us a hint here that says that we can solve this, but just by running pip install pillow.', 'start': 338.442, 'duration': 5.502}, {'end': 348.825, 'text': "Now, if you don't know what pillow is, it's a library for working with images within Python.", 'start': 344.204, 'duration': 4.621}, {'end': 352.286, 'text': 'So we kind of need that for our image field.', 'start': 349.165, 'duration': 3.121}, {'end': 354.207, 'text': "So let's just go ahead and install that.", 'start': 352.607, 'duration': 1.6}, {'end': 356.828, 'text': 'So with pip, we can just say pip install.', 'start': 354.567, 'duration': 2.261}, {'end': 359.109, 'text': 'pillow just like it told us to.', 'start': 357.688, 'duration': 1.421}, {'end': 361.752, 'text': 'If we run that, then it will install that.', 'start': 359.37, 'duration': 2.382}, {'end': 365.515, 'text': "With that installed, let's try to run our make migrations command again.", 'start': 362.152, 'duration': 3.363}], 'summary': "Installing 'pillow' library using 'pip install' to work with images in python.", 'duration': 27.073, 'max_score': 338.442, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI338442.jpg'}, {'end': 425.465, 'src': 'embed', 'start': 396.663, 'weight': 3, 'content': [{'end': 404.571, 'text': 'So now I want to be able to view these user profiles on the admin page of our website so that we can see what this looks like.', 'start': 396.663, 'duration': 7.908}, {'end': 412.539, 'text': 'But if I want to do this, then we have to remember that we need to register this model within the admin file of our app.', 'start': 404.951, 'duration': 7.588}, {'end': 415.622, 'text': 'And this is an easy step to forget, and I do it all the time.', 'start': 412.899, 'duration': 2.723}, {'end': 417.683, 'text': "So let's just go ahead and do that right now.", 'start': 415.922, 'duration': 1.761}, {'end': 425.465, 'text': 'So if we go back to our project within our users app, we have this admin.py file.', 'start': 418.103, 'duration': 7.362}], 'summary': 'Register user profiles in the admin page of the website for better visibility and management.', 'duration': 28.802, 'max_score': 396.663, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI396663.jpg'}, {'end': 521.01, 'src': 'embed', 'start': 492.004, 'weight': 5, 'content': [{'end': 495.267, 'text': "So the users that we've already created don't have profiles yet.", 'start': 492.004, 'duration': 3.263}, {'end': 500.531, 'text': "And we'll set this up in a bit so that when we create users, it also creates a profile for that user.", 'start': 495.607, 'duration': 4.924}, {'end': 503.033, 'text': "But for now, let's just create one manually.", 'start': 501.072, 'duration': 1.961}, {'end': 506.256, 'text': 'So over here to the top right, I can click on Add Profile.', 'start': 503.353, 'duration': 2.903}, {'end': 510.14, 'text': "And let's create a profile for this Query MS user.", 'start': 506.636, 'duration': 3.504}, {'end': 513.203, 'text': 'And I will add an image here.', 'start': 510.72, 'duration': 2.483}, {'end': 521.01, 'text': "So I'll just go to my desktop where I have a few and I'm just going to click on this pic here and upload that and then save.", 'start': 513.563, 'duration': 7.447}], 'summary': 'Users need profiles, system to create profiles automatically.', 'duration': 29.006, 'max_score': 492.004, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI492004.jpg'}, {'end': 576.445, 'src': 'embed', 'start': 551.728, 'weight': 4, 'content': [{'end': 559.851, 'text': "So to demonstrate this, I'm going to stop our dev server for a second and run the Django shell so that we can look at a user profile interactively.", 'start': 551.728, 'duration': 8.123}, {'end': 563.954, 'text': 'So let me pull up the Django shell here.', 'start': 560.231, 'duration': 3.723}, {'end': 571.141, 'text': "So I'm going to stop the dev server and let's run that by saying python manage.py and then shell.", 'start': 563.974, 'duration': 7.167}, {'end': 575.204, 'text': "Okay, so first I'm going to import the built-in Django user model.", 'start': 571.541, 'duration': 3.663}, {'end': 576.445, 'text': "And we've seen this before.", 'start': 575.504, 'duration': 0.941}], 'summary': 'Demonstrating django shell to interact with user profile.', 'duration': 24.717, 'max_score': 551.728, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI551728.jpg'}], 'start': 296.282, 'title': 'Database migrations, pillow installation, and user profile management in django', 'summary': "Discusses running database migrations, resolving 'pillow' library installation error, creating and managing user profiles in django, including registering models, and accessing profile attributes.", 'chapters': [{'end': 359.109, 'start': 296.282, 'title': 'Database migrations and pillow installation', 'summary': "Discusses the process of running database migrations to implement changes and highlights the installation of the 'pillow' library using 'pip' to resolve an error related to the image field.", 'duration': 62.827, 'highlights': ['The process of running database migrations to implement changes over time is emphasized.', "The installation of the 'Pillow' library using 'pip' is highlighted as a solution to resolve the error related to the image field.", "The mention of 'Pillow' as a library for working with images within Python is briefly explained."]}, {'end': 692.7, 'start': 359.37, 'title': 'Managing user profiles in django', 'summary': 'Covers the process of creating and managing user profiles in django, including running migrations, registering models with the admin page, creating user profiles, and accessing profile attributes through the django shell.', 'duration': 333.33, 'highlights': ['The chapter explains the process of registering a user profile model within the admin file of the app, emphasizing the importance of this step and providing a step-by-step guide for the registration process, ensuring a seamless integration with the admin page.', 'The transcript details the steps for accessing user profile attributes through the Django shell, demonstrating how to retrieve and manipulate profile information such as images and their attributes, providing insights into the practical application of Django user profiles.', 'The chapter demonstrates the process of creating user profiles, including adding profile pictures for users, and highlights the automatic creation of a default profile if an image is not provided, showcasing the functionality of user profile creation within a Django web application.']}], 'duration': 396.418, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI296282.jpg', 'highlights': ['The process of running database migrations to implement changes over time is emphasized.', "The installation of the 'Pillow' library using 'pip' is highlighted as a solution to resolve the error related to the image field.", "The mention of 'Pillow' as a library for working with images within Python is briefly explained.", 'The chapter explains the process of registering a user profile model within the admin file of the app, emphasizing the importance of this step and providing a step-by-step guide for the registration process, ensuring a seamless integration with the admin page.', 'The transcript details the steps for accessing user profile attributes through the Django shell, demonstrating how to retrieve and manipulate profile information such as images and their attributes, providing insights into the practical application of Django user profiles.', 'The chapter demonstrates the process of creating user profiles, including adding profile pictures for users, and highlights the automatic creation of a default profile if an image is not provided, showcasing the functionality of user profile creation within a Django web application.']}, {'end': 1000.188, 'segs': [{'end': 715.634, 'src': 'embed', 'start': 693.06, 'weight': 1, 'content': [{'end': 701.885, 'text': 'Now you might be wondering if I was to upload another picture with the file name of pic.jpg, then will it just overwrite this one?', 'start': 693.06, 'duration': 8.825}, {'end': 703.406, 'text': "and it actually wouldn't.", 'start': 702.305, 'duration': 1.101}, {'end': 709.91, 'text': "It would instead just tag on a hash value onto the file name to make sure that duplicate names don't overwrite each other.", 'start': 703.506, 'duration': 6.404}, {'end': 715.634, 'text': "Okay, so let's also look at the profile for the user where we didn't upload an image.", 'start': 710.811, 'duration': 4.823}], 'summary': 'New pictures with duplicate names get hash values to avoid overwriting.', 'duration': 22.574, 'max_score': 693.06, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI693060.jpg'}, {'end': 761.279, 'src': 'embed', 'start': 735.747, 'weight': 0, 'content': [{'end': 743.051, 'text': 'so if i say user dot profile dot image, then we can see that he has a image of default.jpg.', 'start': 735.747, 'duration': 7.304}, {'end': 749.315, 'text': "and we haven't uploaded a default image onto our site to use for users without a picture yet, but we will do that soon.", 'start': 743.051, 'duration': 6.264}, {'end': 754.396, 'text': 'Okay, so now let me exit out of this shell and start our development server again.', 'start': 750.135, 'duration': 4.261}, {'end': 761.279, 'text': "So I'll exit out of this and start the development server again by doing Python manage.py run server.", 'start': 754.417, 'duration': 6.862}], 'summary': "Default image 'default.jpg' assigned to user profile. development server restarted.", 'duration': 25.532, 'max_score': 735.747, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI735747.jpg'}, {'end': 944.848, 'src': 'embed', 'start': 920.608, 'weight': 2, 'content': [{'end': 928.314, 'text': "here is a variable that Django created at the top of our settings file that specifies the location of the project's base directory.", 'start': 920.608, 'duration': 7.706}, {'end': 938.182, 'text': "So basically this is just saying that the media route will be at our project's base directory and then have a directory in there called media.", 'start': 928.735, 'duration': 9.447}, {'end': 941.065, 'text': "Okay, so now let's set the media URL.", 'start': 938.523, 'duration': 2.542}, {'end': 944.848, 'text': 'And the media URL is the public URL of that directory.', 'start': 941.465, 'duration': 3.383}], 'summary': "Django sets the media directory at the project's base directory and specifies the public url.", 'duration': 24.24, 'max_score': 920.608, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI920608.jpg'}], 'start': 693.06, 'title': 'Image upload and media settings in django', 'summary': "Covers image upload and storage, including file name hashing, default images, and changing image locations, as well as configuring media root and media url settings in django's settings.py file, utilizing os module and base_dir variable, and clarifying the purpose of media settings.", 'chapters': [{'end': 826.914, 'start': 693.06, 'title': 'Image upload and storage in django', 'summary': 'Discusses image upload and storage in django, covering file name hashing to prevent overwriting, default image for users without a picture, and changing the location of saved images.', 'duration': 133.854, 'highlights': ['The file name of pic.jpg will not overwrite existing images; instead, a hash value is added to prevent duplicate names from overwriting each other.', "A user with the username 'test user' has a default image named default.jpg, indicating the provision of a default image for users without a picture.", "The directory 'profile pics' is created within the Django project to store uploaded images, located in the same directory as the 'manage.py' file.", "The need to change the settings to avoid cluttering the project's root directory with image directories is highlighted, suggesting the importance of changing the location for saved images."]}, {'end': 1000.188, 'start': 827.395, 'title': 'Configuring media settings in django', 'summary': "Explains how to configure media root and media url settings in django's settings.py file to specify the location for storing uploaded files and the public url for accessing the media, which includes using os module and base_dir variable to create the full path and clarifying the purpose of media root and media url settings.", 'duration': 172.793, 'highlights': ["The media root setting in Django's settings.py file specifies the full path to the directory where uploaded files will be stored, and it can be set using OS module's os.path.join method to create the full path, ensuring the correct directory path across different operating systems.", "The media URL setting in Django's settings.py file defines the public URL of the media directory, enabling access to the uploaded files through the browser with a specified URL format, such as forward slash media.", 'The explanation of how media root and media URL settings work clarifies that media root determines the file system location for uploaded files, while media URL specifies the URL format for accessing the media in the browser, with a specific example of how uploaded images can be accessed at a defined URL.']}], 'duration': 307.128, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI693060.jpg', 'highlights': ["A user with the username 'test user' has a default image named default.jpg, indicating the provision of a default image for users without a picture.", 'The file name of pic.jpg will not overwrite existing images; instead, a hash value is added to prevent duplicate names from overwriting each other.', "The media root setting in Django's settings.py file specifies the full path to the directory where uploaded files will be stored, and it can be set using OS module's os.path.join method to create the full path, ensuring the correct directory path across different operating systems.", "The media URL setting in Django's settings.py file defines the public URL of the media directory, enabling access to the uploaded files through the browser with a specified URL format, such as forward slash media."]}, {'end': 1313.517, 'segs': [{'end': 1025.79, 'src': 'embed', 'start': 1000.489, 'weight': 0, 'content': [{'end': 1006.132, 'text': "Okay, so with those changes that we just made, those actually won't be applied to the profiles that we've already created.", 'start': 1000.489, 'duration': 5.643}, {'end': 1012.335, 'text': 'So we need to go in and remove those two profiles that we created and then recreate those to get these changes to take effect.', 'start': 1006.452, 'duration': 5.883}, {'end': 1015.857, 'text': 'So let me pull up our admin page here.', 'start': 1012.715, 'duration': 3.142}, {'end': 1017.859, 'text': 'and reload this.', 'start': 1016.457, 'duration': 1.402}, {'end': 1021.264, 'text': "and now let's just delete these two profiles that we created.", 'start': 1017.859, 'duration': 3.405}, {'end': 1025.79, 'text': "so i will select delete selected profiles, delete both of those, yes, i'm sure.", 'start': 1021.264, 'duration': 4.526}], 'summary': "Changes won't apply to existing profiles. need to delete and recreate to take effect.", 'duration': 25.301, 'max_score': 1000.489, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1000489.jpg'}, {'end': 1067.183, 'src': 'embed', 'start': 1041.066, 'weight': 2, 'content': [{'end': 1052.015, 'text': 'okay. so with that done, if we go back to our project here, then now we should see a media folder inside the base directory of our project,', 'start': 1041.066, 'duration': 10.949}, {'end': 1057.618, 'text': 'and if we look inside the media folder, then we can see a profile pics directory.', 'start': 1052.015, 'duration': 5.603}, {'end': 1061.02, 'text': 'And inside of there, we can see a pic.jpg.', 'start': 1057.999, 'duration': 3.021}, {'end': 1067.183, 'text': "Now the old profile pics directory is still in our project base directory from before, and that won't be used anymore.", 'start': 1061.26, 'duration': 5.923}], 'summary': 'New media folder with profile pics directory and pic.jpg created, old directory no longer in use.', 'duration': 26.117, 'max_score': 1041.066, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1041066.jpg'}, {'end': 1302.131, 'src': 'embed', 'start': 1275.554, 'weight': 1, 'content': [{'end': 1282.359, 'text': 'So in my browser here, I have the Django documentation pulled up to the managing static files documentation.', 'start': 1275.554, 'duration': 6.805}, {'end': 1286.201, 'text': 'Then let me make this a little bit larger here so that others can see.', 'start': 1282.579, 'duration': 3.622}, {'end': 1290.845, 'text': 'So we can see that it says serving files uploaded by a user during development.', 'start': 1286.802, 'duration': 4.043}, {'end': 1295.048, 'text': 'During development, you can serve user uploaded media files from the media route.', 'start': 1291.185, 'duration': 3.863}, {'end': 1297.809, 'text': 'This is not suitable for production use.', 'start': 1295.708, 'duration': 2.101}, {'end': 1302.131, 'text': 'For some common deployment strategies see deploying static files.', 'start': 1298.13, 'duration': 4.001}], 'summary': 'Django documentation explains serving user uploaded media files during development, not suitable for production use.', 'duration': 26.577, 'max_score': 1275.554, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1275554.jpg'}], 'start': 1000.489, 'title': 'Profile management and image update', 'summary': "Discusses the process of removing and recreating profiles to apply changes, including adding profiles for 'aquariums' and 'test user' without selecting an image. it also covers updating the project to include a media folder, deleting old profile pics, and setting up media routes following django documentation.", 'chapters': [{'end': 1041.066, 'start': 1000.489, 'title': 'Profile management update', 'summary': "Discusses the need to remove and recreate profiles to apply changes, involving deleting two profiles, adding a new profile for 'aquariums', and creating another profile for 'test user' without selecting an image.", 'duration': 40.577, 'highlights': ["The changes made won't be applied to the previously created profiles, requiring the removal and recreation of the profiles to ensure the changes take effect.", 'Deleting the two profiles and creating new ones allows the changes to take effect.', "Adding a profile for 'aquariums' and uploading a picture, followed by creating another profile for 'test user' without selecting an image, demonstrates the process of recreating profiles."]}, {'end': 1313.517, 'start': 1041.066, 'title': 'Updating profile page with user images', 'summary': 'Covers updating the project to include a media folder, deleting old profile pics, displaying user information on the profile page, and setting up media routes following django documentation.', 'duration': 272.451, 'highlights': ['The project is updated to include a media folder, and old profile pics are deleted from the base directory. The media folder is added to the base directory, and old profile pics are deleted to make way for new images. This ensures a clean file structure and allows for the display of user images.', "User information such as username, profile picture, and email address is displayed on the profile page. The profile page is updated to display the user's username, profile picture, and email address. This enhances the user experience by providing relevant information at a glance.", 'Media routes are set up following the Django documentation for serving user uploaded media files during development. The process of setting up media routes is explained, in line with Django documentation, to serve user uploaded media files during development. This ensures that media files can be accessed and displayed correctly within the project.']}], 'duration': 313.028, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1000489.jpg', 'highlights': ['Deleting the two profiles and creating new ones allows the changes to take effect.', 'The process of setting up media routes is explained, in line with Django documentation, to serve user uploaded media files during development. This ensures that media files can be accessed and displayed correctly within the project.', 'The project is updated to include a media folder, and old profile pics are deleted from the base directory. The media folder is added to the base directory, and old profile pics are deleted to make way for new images. This ensures a clean file structure and allows for the display of user images.']}, {'end': 2128.082, 'segs': [{'end': 1337.092, 'src': 'embed', 'start': 1313.517, 'weight': 3, 'content': [{'end': 1323.522, 'text': 'so it says, for example, if your media URL is defined as media, then you can do this by adding the following snippet to your projects urls.py file.', 'start': 1313.517, 'duration': 10.005}, {'end': 1331.627, 'text': 'and we can see here that they are importing the settings and importing static and then just adding this on to our url patterns.', 'start': 1323.522, 'duration': 8.105}, {'end': 1337.092, 'text': "now i'm going to take their code block that they suggested here and i'm going to alter it just slightly.", 'start': 1331.627, 'duration': 5.465}], 'summary': 'Guide explains how to modify media url in projects urls.py file.', 'duration': 23.575, 'max_score': 1313.517, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1313517.jpg'}, {'end': 1400.335, 'src': 'heatmap', 'start': 1346.439, 'weight': 0.821, 'content': [{'end': 1350.443, 'text': 'so within our project we are going to open urls.py.', 'start': 1346.439, 'duration': 4.004}, {'end': 1356.168, 'text': 'scroll down here a little bit and now let me paste in what i got from their website.', 'start': 1350.443, 'duration': 5.725}, {'end': 1358.71, 'text': 'so this is what it said to do in their website.', 'start': 1356.168, 'duration': 2.542}, {'end': 1363.934, 'text': 'so it said to import the settings and import static using these lines here.', 'start': 1358.71, 'duration': 5.224}, {'end': 1365.316, 'text': "so i'm going to go ahead and do that.", 'start': 1363.934, 'duration': 1.382}, {'end': 1371.021, 'text': "so i will copy those and i'll move them up here towards the top and save that.", 'start': 1365.316, 'duration': 5.705}, {'end': 1380.625, 'text': 'now we also have our url patterns here and it says just to add the static media url here onto the end.', 'start': 1371.701, 'duration': 8.924}, {'end': 1387.989, 'text': "now i'm pretty sure that they check the debug settings for you if you were to add this on, but i kind of like to be a little bit more explicit.", 'start': 1380.625, 'duration': 7.364}, {'end': 1400.335, 'text': "so instead i'm just going to actually say that if our settings and settings is something that we imported up here, so if settings dot debug,", 'start': 1387.989, 'duration': 12.346}], 'summary': 'Adding import settings and static, updating url patterns.', 'duration': 53.896, 'max_score': 1346.439, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1346439.jpg'}, {'end': 1442.55, 'src': 'embed', 'start': 1419.069, 'weight': 5, 'content': [{'end': 1426.295, 'text': 'I just like doing it this way, instead of adding it directly to our URL patterns up here, because if anybody else is reading our code,', 'start': 1419.069, 'duration': 7.226}, {'end': 1433.021, 'text': "then it's a little bit more understandable what this is doing, that we're only adding this on when we're in debug mode.", 'start': 1426.295, 'duration': 6.726}, {'end': 1442.55, 'text': 'Okay, so now with our media URL and our media route added to our URL patterns, now this should now allow our media to work within the browser.', 'start': 1433.321, 'duration': 9.229}], 'summary': 'Media route added for debug mode, enhancing code readability.', 'duration': 23.481, 'max_score': 1419.069, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1419069.jpg'}, {'end': 1621.617, 'src': 'heatmap', 'start': 1558.314, 'weight': 0, 'content': [{'end': 1563.777, 'text': "So I'm going to open that media folder, and we can see that we have our profile pics directory there.", 'start': 1558.314, 'duration': 5.463}, {'end': 1569.621, 'text': "Now our default.jpg, I'm just going to paste right in our media folder.", 'start': 1564.278, 'duration': 5.343}, {'end': 1578.146, 'text': 'So once we have that pasted into our media folder, if we go back to the browser and reload this page, then now it can see that default.jpg image.', 'start': 1569.961, 'duration': 8.185}, {'end': 1583.531, 'text': "OK, so now that we have that working, There's one more thing that I want to do before finishing up this video.", 'start': 1578.566, 'duration': 4.965}, {'end': 1590.258, 'text': 'So right now we have a pretty nice user system where users have these profile pages and profile pictures,', 'start': 1583.951, 'duration': 6.307}, {'end': 1596.865, 'text': "but we'll want to make sure that for every new user that is created, they automatically get a profile as well,", 'start': 1590.258, 'duration': 6.607}, {'end': 1599.108, 'text': 'which would include the default profile picture.', 'start': 1596.865, 'duration': 2.243}, {'end': 1607.593, 'text': 'Because the way that this is set up right now, We actually have to go into the admin page and create the profiles for each of our users.', 'start': 1599.769, 'duration': 7.824}, {'end': 1609.873, 'text': "And we don't want to do that every time.", 'start': 1608.033, 'duration': 1.84}, {'end': 1612.114, 'text': 'So this is fairly easy to do.', 'start': 1610.233, 'duration': 1.881}, {'end': 1616.255, 'text': 'So what we need to do here is to add something called a Django signal.', 'start': 1612.274, 'duration': 3.981}, {'end': 1621.617, 'text': "And we're going to create a new file in our users app called signals where we can write this.", 'start': 1616.655, 'duration': 4.962}], 'summary': 'Automating profile creation for new users using django signal and default.jpg.', 'duration': 43.051, 'max_score': 1558.314, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1558314.jpg'}, {'end': 1675.941, 'src': 'heatmap', 'start': 1626.119, 'weight': 1, 'content': [{'end': 1632.802, 'text': 'And let me close down some of the files that we have previously been working with since this is getting a little cluttered here.', 'start': 1626.119, 'duration': 6.683}, {'end': 1639.945, 'text': "So now in our users app, we're going to create a file inside our users app.", 'start': 1633.703, 'duration': 6.242}, {'end': 1643.767, 'text': "And we're going to call this signals.py.", 'start': 1640.266, 'duration': 3.501}, {'end': 1649.35, 'text': "Now you'll see some people put these signals in the models.py file where we created the profile model.", 'start': 1644.127, 'duration': 5.223}, {'end': 1655.252, 'text': 'But the Django documentation recommends doing it this way to avoid some side effects of how imports work.', 'start': 1649.73, 'duration': 5.522}, {'end': 1659.434, 'text': "So we're going to import a signal called post save.", 'start': 1655.973, 'duration': 3.461}, {'end': 1671.579, 'text': 'So within the signals.py file we can say from Django let me spell that right from Django.db.models.signals.', 'start': 1659.794, 'duration': 11.785}, {'end': 1675.941, 'text': 'we want to import post underscore, save now.', 'start': 1671.579, 'duration': 4.362}], 'summary': 'Creating signals.py file in users app, importing post save signal from django.db.models.signals to avoid side effects of imports.', 'duration': 49.822, 'max_score': 1626.119, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1626119.jpg'}, {'end': 1730.674, 'src': 'embed', 'start': 1702.91, 'weight': 2, 'content': [{'end': 1708.834, 'text': "since it is going to be what is sending the signal, and we're also going to need to create a receiver.", 'start': 1702.91, 'duration': 5.924}, {'end': 1715.178, 'text': 'a receiver is going to be a function that gets this signal and then performs some task.', 'start': 1708.834, 'duration': 6.344}, {'end': 1718.4, 'text': 'so we need to also import the receiver.', 'start': 1715.178, 'duration': 3.222}, {'end': 1727.231, 'text': "so i'll say from django dot dispatch import receiver and save that Now.", 'start': 1718.4, 'duration': 8.831}, {'end': 1730.674, 'text': "in these long imports here it's always easy to make some spelling mistakes.", 'start': 1727.231, 'duration': 3.443}], 'summary': 'Creating a receiver function to process signals in django.', 'duration': 27.764, 'max_score': 1702.91, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1702910.jpg'}, {'end': 1972.565, 'src': 'heatmap', 'start': 1925.139, 'weight': 0.914, 'content': [{'end': 1931.343, 'text': "so we'll say instance, which is going to be the user instance dot, profile dot, save.", 'start': 1925.139, 'duration': 6.204}, {'end': 1933.725, 'text': 'okay, so that is going to do it for our signals.', 'start': 1931.343, 'duration': 2.382}, {'end': 1937.726, 'text': "Now there's still one little small step that we have to do before this will work.", 'start': 1934.065, 'duration': 3.661}, {'end': 1944.287, 'text': 'So we have to import our signals inside of the ready function of our users apps.py file.', 'start': 1938.066, 'duration': 6.221}, {'end': 1953.929, 'text': "So let's go inside of our users app and in the apps.py module that we've seen already within our users config.", 'start': 1944.667, 'duration': 9.262}, {'end': 1959.49, 'text': 'here we are going to create a function or a method in here called ready.', 'start': 1953.929, 'duration': 5.561}, {'end': 1962.371, 'text': 'And that is going to take self as the first argument.', 'start': 1959.91, 'duration': 2.461}, {'end': 1967.418, 'text': 'and within this ready method, we are just going to import those signals.', 'start': 1962.891, 'duration': 4.527}, {'end': 1972.565, 'text': "so we'll say import users, dot signals and, like i was saying before,", 'start': 1967.418, 'duration': 5.147}], 'summary': 'The transcript discusses importing signals in the users app to enable user profile saving.', 'duration': 47.426, 'max_score': 1925.139, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1925139.jpg'}], 'start': 1313.517, 'title': 'Configuring media url and user profile setup in django', 'summary': 'Covers adding media url to projects urls.py, importing settings and static, and configuring url patterns, as well as setting up user profile page with default image and utilizing django signals for automatic user profile creation, streamlining user management and enhancing user experience.', 'chapters': [{'end': 1442.55, 'start': 1313.517, 'title': 'Adding media url to projects urls.py', 'summary': 'Discusses adding a media url to the projects urls.py file, importing settings and static, and making alterations to the url patterns to allow media to work within the browser.', 'duration': 129.033, 'highlights': ['The chapter discusses adding a media URL to the projects urls.py file', 'Importing settings and static to enable the media URL', 'Making alterations to the URL patterns to allow media to work within the browser']}, {'end': 2128.082, 'start': 1442.89, 'title': 'User profile page and django signals', 'summary': 'Demonstrates setting up the user profile page with a default image and implementing django signals to automatically create a user profile upon user creation, resulting in a streamlined user management process and improved user experience.', 'duration': 685.192, 'highlights': ['Implemented user profile page with default image and user details, improving user experience.', 'Utilized Django signals to automatically create user profiles upon user creation, streamlining the user management process.', 'Demonstrated the process of setting up Django signals by creating a signals.py file and using post save signal for user creation events.', 'Explained the usage of decorators and receivers in Django signals to trigger functions upon specific events, enhancing understanding of signal handling in Django.']}], 'duration': 814.565, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdVuKt_iuSI/pics/FdVuKt_iuSI1313517.jpg', 'highlights': ['Implemented user profile page with default image and user details, improving user experience.', 'Utilized Django signals to automatically create user profiles upon user creation, streamlining the user management process.', 'Explained the usage of decorators and receivers in Django signals to trigger functions upon specific events, enhancing understanding of signal handling in Django.', 'The chapter discusses adding a media URL to the projects urls.py file', 'Importing settings and static to enable the media URL', 'Making alterations to the URL patterns to allow media to work within the browser']}], 'highlights': ['Utilized Django signals to automatically create user profiles upon user creation, streamlining the user management process.', 'The process of setting up media routes is explained, in line with Django documentation, to serve user uploaded media files during development. This ensures that media files can be accessed and displayed correctly within the project.', 'The chapter demonstrates the process of creating user profiles, including adding profile pictures for users, and highlights the automatic creation of a default profile if an image is not provided, showcasing the functionality of user profile creation within a Django web application.', 'The process of running database migrations to implement changes over time is emphasized.', "The installation of the 'Pillow' library using 'pip' is highlighted as a solution to resolve the error related to the image field.", "The media URL setting in Django's settings.py file defines the public URL of the media directory, enabling access to the uploaded files through the browser with a specified URL format, such as forward slash media.", "The media root setting in Django's settings.py file specifies the full path to the directory where uploaded files will be stored, and it can be set using OS module's os.path.join method to create the full path, ensuring the correct directory path across different operating systems.", 'The chapter explains the process of registering a user profile model within the admin file of the app, emphasizing the importance of this step and providing a step-by-step guide for the registration process, ensuring a seamless integration with the admin page.', 'The chapter introduces creating a user profile model in the users app. It explains the process of creating a new model in the users app and opening the models.py file to work on the profile model.', 'Extending the user model to add fields for a profile picture and creating a new profile model with a one-to-one relationship with the user.']}