亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ModelForm 中的圖像未保存

ModelForm 中的圖像未保存

萬千封印 2024-01-27 16:04:03
我在 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



查看完整回答
反對 回復 2024-01-27
  • 1 回答
  • 0 關注
  • 192 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號