这是一个非常菜鸟的问题,但我无法弄清楚。我想在我的 Django 模板中为 2 个(或者可能最终更多)表单使用单个提交。这是我在模板中所做的,但显然不正确。
<html><body>
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<p>Please insert .raw file {{ form }} </p>
</form>
<form action="" method="post" enctype="multipart/form-data">
<p>Please insert .xml file {{ form }} </p>
<input type="submit" value="Confirm" />
<input type="reset" value="Reset" class="button">
</form>
我的 forms.py 文件看起来像这样
from django import forms # for UploadFileForm
class DocumentForm(forms.Form): docfile = forms.FileField(label='选择一个文件', help_text='文件大小没有限制')
这是我的看法
def Upload(request):
# Handle file upload
if request.method == 'POST': # If form is submitted
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
# Redirect to Processing window until processing is complete
return HttpResponseRedirect('') # Takes me right back to the upload Page
else:
return render_to_response(
'Upload.html',
{'form': form},
context_instance=RequestContext(request)
)
提前致谢!