Image File Upload to User Profile Model | Django (3.0) Crash Course Tutorials (pt 17)

preview_player
Показать описание

Upload Images to User Profile model and display images dynamically

Рекомендации по теме
Комментарии
Автор

0:50 adding ImageField in Model
2:52 set MEDIA_ROOT in settings.py
5:30 add MEDIA_URL in urls.py urlpatterns
11:30 add input image field in view and template
15:07 default image

junecnol
Автор

best Django playlist on youtube.
I learned a lot throughout the series from basics to advance, to create an entire application
with covering concepts, thank you man

balaji
Автор

Dennis, no lie you have the BEST django react tutorials out there. Keep it up, you're big but you deserve 20x the subs.

robxnguyen
Автор

Hey Brother, I really want to appreciate your work. I say a whole bunch of THANK YOU. I jumped to Python from PHP and for months now it have been very difficult till i saw your videos.

this is the very first youtube channel i have subscribed to. God bless you for me .

brownhillobinna
Автор

I think you have explained concepts very well as compared to others in youtube(django).

hemantagarwal
Автор

The keyboard clicks are too good and satisfying... and the Tutorial is very clear and easy to understand

priteshwani
Автор

I LOVE YOU BRO. SAVED ME A LOT OF TIME . Hands down one of the best coding tutorials out there !!!!

frost
Автор

I'm so tired that I just tried to close YOUR tabs. On a brighter note, this tutorial was really easy to understand and very clear.

WhitneyChakara
Автор

Thanks for all your content! You said that a redirect needed to be added upon saving the form in the accountSettings function but didnt add the code for us. I realized without it, when the form is submitted it would not show the updated form information (e.g. if you delete an image or add one, you'd have to manually refresh the page, which could lead to duplication of data). So for anyone reading, add this after return redirect('/account')

Copt
Автор

It is my first time to watch your tutorial.
You are so wonderful!

JustForFun-tk
Автор

Hey Dennis, there is a small problem. When a user registers then a default image is set to his/her profile. Then if user adds/uploads a new profile picture then the default profile image will be overwritten with the new one. Now the problem is if the user clears/deletes his/her profile picture instead of choosing/uploading another one, then there will be no file in the 'profile_pic' field. And this causes an error when trying to go to the 'setting' URL.
So what I came up with is not to set a default file in ImageField, and fetch the default image if the user has no profile image in the 'profile.html' template.
In profile.html:
{% if %}
<img class="profile-pic"
{% else %}
<img class="profile-pic" src="{% static %}">
{% endif %}

ritiksaxenaofficial
Автор

I have been following this entire series. Very helpful and informative, looking forward to watching more educational content produced by you Dennis. Thank you for your effort!

MRROCKMAST
Автор

That might be the best tutorial on YouTube that explains the whole ImageField process. Thanks Dennis

jimshapedcoding
Автор

Спасибо!) Без вашего курса я бы еще долго думал почему выводиться imagefield.)

НикитаПосмак
Автор

For Django 3.1, for the MEDIA_ROOT variable in settings.py, do this: MEDIA_ROOT = BASE_DIR/"static/images"

If that doesn't work, then see if your static folder is somehow not in the same directory or just in your accounts folder (like it was for me). Move it to outside the accounts folder.

DarkStarRules
Автор

When we update the image, the old image stays in the images file, how do we get rid of that?

paristonhill
Автор

Hi Dennis, thanks for this excellent contribution to the developer community. Having gone through your tut, it seems like it is designed for a call-in order system whereby only an admin can create, update, or delete an order. I tried modifying some of the templates and scripts to enable a user create, update, delete an order from their user template but not successful. This is because the respective tables need reference (primary key) to a customer and/or order to work. Not sure how to modify code to recognize that current user/customer is the pk (id) that should be referenced. I agree that only an admin should be able to see all customers and their orders but each customer should be able to not only see their own orders but be able to generate new orders, update or delete current orders that have not been shipped. Your help is appreciated sir. And I welcome those who may have answers to this inquiry to so provide with equal gratitude from me to you.

DejAyEnterprise
Автор

Tutorial on how to place order as customer would be great!

gel.ventures
Автор

If you are running your server at the beginning just after inserting in the Customer model the profile_pic's Image field, a red message will tell you, "Cannot use ImageField because Pillow is not installed"

Just CTRL+C when running server and run the following command : python -m pip install Pillow

For information, Pillow is a Python module responsible for opening/importing pictures, and Django seems to be using it in its backend to manage pictures.

skanda
Автор

django 3.1 version -
urlpatterns = [
    ...
] + static(settings.MEDIA_URL,  document_root=settings.MEDIA_ROOT)

johndwick