gpt4 book ai didi

python - 此字段为必填错误,但字段格式为

转载 作者:行者123 更新时间:2023-12-01 08:19:25 25 4
gpt4 key购买 nike

所以我有一个用 request.POST 初始化的表单,但是,即使该表单具有正确的字段,它也无效,我缺少什么?

def some_view(self, request):
form = SomeForm(request.POST or None)
if form.is_valid():

(Pdb) form.data
<QueryDict: {u'csv_file': [u'some_csv_file.csv'], u'csrfmiddlewaretoken': [u'csrftoken']}>
(Pdb) form.is_valid()
False
(Pdb) form.errors
{'csv_file': [u'This field is required.']}

最佳答案

当 Django 表单中有一个 FileField 时,需要做两件事:

1. In your template, in the form tag, add enctype="multipart/form-data"
<form method="POST" action="" enctype="multipart/form-data">

2. Pass the request.FILES when creating the form
form = SomeForm(request.POST or None, request.FILES)

关于python - 此字段为必填错误,但字段格式为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54762301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com