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

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

django ModelForm 不捕獲上傳的圖像

django ModelForm 不捕獲上傳的圖像

慕的地6264312 2023-08-08 09:50:34
您好,我正在嘗試為我的網站上的用戶創建一個表單,以便能夠添加產品,我使用 ModelForm 制作了該表單,并且我已設法在我的模板中呈現它,但它沒有按要求運行。提交表單時,我不斷收到驗證錯誤,表明圖像尚未提交,但我確實添加了它們,有什么想法嗎模型from django.db import modelsclass Product(models.Model):    name = models.CharField(max_length=120)    price = models.FloatField()    image_182x182 = models.ImageField(upload_to='pdt_imgs/')    image_1200x1200 = models.ImageField(upload_to='pdt_imgs/alt_imgs/')    image_600x600 = models.ImageField(upload_to='pdt_imgs/alt_imgs/')    image_600x600_2 = models.ImageField(upload_to='pdt_imgs/alt_imgs/')    image_300x300 = models.ImageField(upload_to='pdt_imgs/alt_imgs/')    img_array = [image_1200x1200, image_600x600, image_600x600_2]    sku = models.IntegerField()    available = models.BooleanField(default=True)    discount = models.IntegerField(default = 0)    category = models.ForeignKey(SubCategory, on_delete=models.CASCADE)    seller = models.ForeignKey(Seller, on_delete=models.CASCADE)       def __str__(self):        return self.name    def get_absolute_url(self):        return  reverse('pdt_detail', args=[str(self.id)])    def get_add_to_cart_url(self):        return reverse('add-to-cart', args= [str(self.id)] )   形式from .models import Productfrom django.forms import ModelFormclass ProductForm(ModelForm):    class Meta:        model = Product        fields = [            'name', 'price', 'image_182x182', 'image_1200x1200', 'image_600x600',            'image_600x600_2', 'image_300x300', 'sku', 'available', 'discount',             'category', 'seller'            ]意見from django.utils.decorators import method_decoratorfrom .decorators import seller_requiredfrom django.views.generic import CreateViewfrom store.models import Productfrom store.forms import ProductFormfrom django.contrib import messages
查看完整描述

1 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

   <form class="ps-form--account-setting"  method="post" enctype="multipart/form-data">



查看完整回答
反對 回復 2023-08-08
  • 1 回答
  • 0 關注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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