我有一个带有文件上传字段的表单,该字段将显示在模板中
提交表单后,如果发现错误并返回页面,上传文件将消失,谁能帮我了解如何在发现错误后在表单页面中显示上传文件
以下是表格:
class Project_f(forms.Form):
info=forms.CharField(required=True)
file=forms.FileField(required=False)
和模板:
<form action="" method="post" id="form1" enctype="multipart/form-data" ....>
{% csrf_token %}
<td ><label for="id_info">product info:</label></td>
<td colspan=3 >{{form.info}}</td>
<td > </td>
</tr>
<tr class="tr_blank"></tr>
<tr>
<td > </td>
<td><label for="id_attachement_id">add attachment:</label></td>
{% if attachments %}
{% for attachment in attachments %}
<td colspan="2">
current attachment:<div class='attachmentdd'id={{attachment.id}}><a href={{attachment.file}}>{{attachment.file}}</a>
<br>modify:<input id="txt" class="input_text" type="file" name="attachement_id" style="width:100%;height:23px;">
</div>
{% endfor %}
{% else %}
<td >{{form.attachement_id}}</td>
{% endif %}
<td > </td>
</tr></form>
以下是views.py
Pr_form=Project_f(request.POST,request.FILES)
if Pr_form.is_valid():
......
else:
c={'form': Pr_form,'user':login_name,'ourteam':ourteam}
c.update(csrf(request))
return render_to_response('project_form.html',c,context_instance=RequestContext(request))
提交表单后,如果服务器发现错误,显示错误信息时不会显示上传文件路径