Views.py 我无法弄清楚问题是什么。我一直在尝试许多其他但无济于事。请帮助理清这个小问题
def user_account_dp(request):
if request.method == "POST":
modelform = modelformimage(request.POST,request.FILES,instance=request.user.userdp)
if user_profile_pic_fm.is_valid():
user_profile_pic_fm.save()
messages.success(request,'Successfully updated Profile')
return redirect('gbiz1990:profile_account')
else:
messages.error(request,'chose a picture')
else:
user_profile_pic_fm =DpForm(instance=request.user.userdp)
return render(request,"gbiz1990/user_account/user_profile.html",{'user_profile_pic_fm':user_profile_pic_fm})
html.file
<form action='{{ action_url}}' method='post' enctype="multipart/form-data">
{{ user_profile_pic_fm.profilepic}} {% csrf_token %} <button type="submit">Save changes</button></form>
model.py
enter code here
class UserDp(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE,related_name="userdp")
profilepic =models.ImageField(upload_to="profile_image",null=True,blank=False)
def __str__(str):
return self.profilepic
@receiver(post_save,sender=User)
def create_user_userdp(sender,instance,created,**kwargs):
if created:
UserDp.objects.create(user=instance)