我正在尝试上传图片,但form.is_valid总是返回false
def upload(request):
if request.method=="POST":
form=uploadform(request.POST,request.FILES)
if form.is_valid():
cd=cleaned_data
form.save(commit=True)
return render(request,"success.html")
else:
form=uploadform()
return render(request,'pico.html',{'form':form})
这是表格
<form action="" method="post">
{{form.as_p}}
{% csrf_token %}
<input type="submit" value="Submit" />
</form>
class uploadform(ModelForm):
class Meta:
model=examplemodel
fields=['pic']
class examplemodel(models.Model):
pic=models.ImageField()
答案 0 :(得分:0)
您是否在html表单标签中设置了enctype="multipart/form-data"
?