В корневой папке проекта есть папка media,
settings
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls
if not settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
models
class Customer(models.Model):
user = models.ForeignKey(User, verbose_name='Пользователь', on_delete=models.CASCADE, blank=True, null=True)
avatar = models.ImageField("Аватар", upload_to="photos/", blank=True, null=True)
date = models.DateField("Дата создания", auto_now=True, auto_now_add=False, blank=True, null=True)
def __str__(self):
return f'{self.user}'
class Meta:
verbose_name = "Профиль пользователя"
verbose_name_plural = "Профиль пользователей"
ordering = ('id',)
def profile_absolute_url(self):
return reverse('profile_detail', kwargs={'pk': self.id})
views
class ProfileDetail(DetailView):
model = Customer
context_object_name = 'profile'
template_name = 'Pay/profile_detail.html'
html
<p><img src="{{ profile.avatar.url }}"></p>
<p>{{ profile.user }}</p>
<p>{{ profile.date }}</p>