django self.request.files.getList
因此,我已将输入的名称属性更改为一些自定义名称,但是视图调用 form_invalid 方法。为什么我的表格没有保存(验证)?
html:
<tr>
<th><label for="id_photo">Image:</label></th>
<td>
<input type="file" name="custom_photo_name" accept="image/*" required id="id_photo" multiple>
</td>
</tr>
表单:
class DateForm(forms.ModelForm):
photo = forms.ImageField(required=False)
class Meta:
model = Date
exclude = ('user',)
视图:
class UpdateDateView(LoginRequiredMixin, UpdateView):
model = Date
form_class = DateForm
template_name = 'app/form/date_edit_form.html'
@transaction.atomic
def form_valid(self, form):
date = form.save()
self.request.FILES.getlist('custom_photo_name') # this returns an empty list []
return super().form_valid(form)
self.request.files不根据 name 属性来获得值?为什么我不能联系我的文件?
So I have changed the input's name attribute to some custom name, but the view calls form_invalid method. Why my Form isn't saving (validating)?
html:
<tr>
<th><label for="id_photo">Image:</label></th>
<td>
<input type="file" name="custom_photo_name" accept="image/*" required id="id_photo" multiple>
</td>
</tr>
the form:
class DateForm(forms.ModelForm):
photo = forms.ImageField(required=False)
class Meta:
model = Date
exclude = ('user',)
the view:
class UpdateDateView(LoginRequiredMixin, UpdateView):
model = Date
form_class = DateForm
template_name = 'app/form/date_edit_form.html'
@transaction.atomic
def form_valid(self, form):
date = form.save()
self.request.FILES.getlist('custom_photo_name') # this returns an empty list []
return super().form_valid(form)
Doesn't the self.request.FILES takes the values according to name attribute? Why can't I reach my files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论