我對圖像和圖像域有疑問。但是,我選擇的默認圖片不顯示,只有一個空白的圓圈。這是我default pictureDjango - 默認個人資料圖片不顯示
Models.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
description = models.CharField(max_length=255, default='')
city = models.CharField(max_length=100, default='')
website = models.URLField(default='')
def __str__(self):
return self.user.username
class ProfilePicture(models.Model):
user = models.ForeignKey(User)
image = models.ImageField(upload_to='profile_image', default='profile_image/Default.jpg')
Forms.py
class UploadPictureForm(forms.Form):
image = forms.ImageField()
profile.html
<div class="container">
<div id="left">
<div id="profilecard">
{% if user.userprofile.image %}
<img class="circular--square" src="{{ }}" width="200" height="200">
{% endif %}
<div id="info">
<br>
<h3>{{ user.first_name }} {{ user.last_name }}</h3>
<p>@{{ user }}</p>
<p>{{ user.userprofile.city }}</p>
<p>{{ user.userprofile.website }}</p>
<p><i>{{ user.userprofile.description }}</i></p>
</div>
</div>
你能解釋一下你用你的外鍵related_name是什麼意思? – lordVader
更新了我的答案 –