我正在使用Django开发网站,我想使用HTML模板中的dropzone框上传文件,然后将其发送到查看功能并发送一些消息(如果文件已成功上传) 这是HTML模板(inputFile_pannel.html)中的代码:
<p>{{mess}}</p>
<form action="{% url 'upload_file' %}" enctype="multipart/form-data" class="dropzone" id="myDropzone" >
{% csrf_token %}
</form>
这是视图函数(uplosd_file):
@login_required
def upload_file(request):
uploaded_file_url=''
mess=''
if request.method == 'POST' and request.FILES['file']:
myfile = request.FILES['file']
fs = FileSystemStorage()
filename = fs.save(myfile.name, myfile)
uploaded_file_url = fs.url(filename)
mess='The file is uploade successfully, you can check the status in your pannel'
return render(request, 'app/inputFile_pannel.html', {
'mess':mess
})
return render(request, 'app/inputFile_pannel.html', {
'mess':mess
})
但是mess变量没有出现在网页上,有人可以说出什么问题吗?
答案 0 :(得分:0)
<form action="{% url 'upload_file' %}" enctype="multipart/form-data" class="dropzone" id="myDropzone" **method="POST"**>
您必须将方法设为POST ...,否则您的请求将为GET。