R
R
Rassul Nassyrov2020-09-17 14:04:10
Django
Rassul Nassyrov, 2020-09-17 14:04:10

How to save a user's photo and change it?

For some reason I can't figure out how to save user files/photos to a folder and change them.
You can give an example of an ImageField to anyone who is not difficult - models.py, views.py, html on DJANGO.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2020-09-17
@Mi11er

models.py

photo= models.ImageField(verbose_name='Фотография',
                             upload_to='photos/%Y/%m/%d',
                             blank=True)

Here is from the template
<div class="user_img">
   <img src="{% if user.photo %}{{ user.photo.url }}{% else %}{% static 'sysadmins/img/avatar.jpg' %}{% endif %}" alt="">
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question