Answer the question
In order to leave comments, you need to log in
Why doesn't it display the user's photo?
In the root folder of the project there is a folder media,
settings
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
if not settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
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})
class ProfileDetail(DetailView):
model = Customer
context_object_name = 'profile'
template_name = 'Pay/profile_detail.html'
<p><img src="{{ profile.avatar.url }}"></p>
<p>{{ profile.user }}</p>
<p>{{ profile.date }}</p>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question