形式
from django import forms
class XLSForm(forms.Form):
xlsx_file = forms.FileField(help_text="The XLSX file")
column_1 = forms.ChoiceField(help_text="Column 1 from XLSX")
column_2 = forms.ChoiceField(help_text="Column 2 from XLSX")
kaka = forms.CharField(help_text="Column 2 from XLSX")
视图:
def IndexView(request):
if request.method == 'POST':
form = XLSForm(request.POST, request.FILES)
else:
form = XLSForm()
context = {
'form': form
}
return render(request, 'xlsplot.html', context)
和模板:
<form method="post" novalidate>
{% csrf_token %}
{{form}}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
每当我提交从计算机中选择的文件时,文件字段将重置为“未选择文件”,错误显示为“此字段是必需的”。其他输入似乎工作正常,如果它们没有错误。我不明白
嗯。我很笨。我忘了在表单中添加
enctype="multipart/form-data"
。案件结案相关问题 更多 >
编程相关推荐