我在 wagtail 中有一个 Pgae 模型,它持有一个 ImageField:from django.conf import settingsfrom wagtail.users.models import upload_avatar_tofrom django.utils.translation import gettext_lazy as _class ProfilePage(Page): avatar = models.ImageField( # Also updated from user.wagtail_userprofile.avatar verbose_name=_("profile picture"), upload_to=upload_avatar_to, blank=True, ) intro = RichTextField( blank=True, null=True, verbose_name=_("Personal introduction"), help_text=_("maximum number of characters: 80 characters"), max_length=80, ) school = models.CharField( verbose_name=_("School name"), max_length=100, blank=True, null=True ) school_details = models.CharField( blank=True, null=True, verbose_name=_("School details"), help_text=_("example: Faculty of Medicine"), max_length=100, ) location = models.CharField( verbose_name=_("Location"), max_length=50, blank=True, null=True, help_text=_("example: Osaka"), ) user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, verbose_name=_("User") )我需要创建一个模型表单,因为我正在渲染自定义模板以在注册后设置个人资料:from django import formsfrom django.forms import ModelFormclass ProfilePageDetailsForm(ModelForm): intro = forms.CharField( required=False, widget=forms.Textarea, label=_("Personal introduction"), help_text=_("maximum number of characters: 80 characters"), max_length=80, ) class Meta: model = ProfilePage fields = [ "avatar", "title", "school", "location", "intro", ]单击提交并填写包括头像字段在内的所有字段后,我成功重定向到 wagtail 管理页面,但是当我检查个人资料页面时,头像图像不存在,我尝试调试,但在该过程中没有发现任何错误非常欢迎帮助或建议,非常感谢
1 回答
胡说叔叔
TA贡献1804条经验 获得超8个赞
当您在视图中重新绑定表单时,您需要通过 -request.FILES
请参阅https://docs.djangoproject.com/en/3.1/topics/http/file-uploads/request.POST
添加回答
举报
0/150
提交
取消