将封面图像上传到 Django 的用户扩展模型时,我没有收到任何错误,但我看不到我在做什么,因为它没有给出任何错误,甚至没有更新我的模型。不过,我可以通过使用这个概念来更改简介,但我无法将封面图像更新为我的用户扩展模型。这里我给出源码
models.py
class Memer(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
mobile = models.CharField(max_length=16, blank=True, null=True)
bio = models.CharField(max_length=150, blank=False, null=False, default="Hey! I'm new here.")
cover = models.ImageField(upload_to='cover-images/%y/%m/%d/', default='cover-images/default/memerrank-bg.jpg', blank=False, null=False)
profile = models.ImageField(upload_to='profile-images/%y/%m/%d/', default='profile-images/default/memerrank-no-dp.jpg', blank=False, null=False)
def __str__(self):
return str(self.user)
forms.py
class UpdateCoverImageForm(forms.ModelForm):
class Meta:
model = Memer
fields = ['cover']
views.py
def profile(request, username):
try:
user = User.objects.get(username=username)
user_ = User.objects.filter(username=username)
memer = Memer.objects.filter(user=user_[0].id)
except User.DoesNotExist:
raise Http404("Memer does not exist.")
context = {
'user_': user_,
'memer': memer,
}
沧海一幻觉
12345678_0001
相关分类