我是Django的新手,我正在学习如何使用django处理上传文件,我对文档做了同样的事情,但我的nginx只是抛出错误,
这是我的views.py:
@csrf_exempt
def upload_view(request):
if request.method == 'POST':
form = UploadItemForm(request.POST, request.FILES)
if form.is_valid():
return HttpResponse('successfully uploaded')
else:
return HttpResponse('upload failed')
else:
if request.user.is_authenticated():
form = UploadItemForm()
return render(request,
'design/upload.html',
{'form': form,
'username': request.user.username})
else:
return HttpResponse("you have to login")
model.py
class Item(models.Model):
name = models.CharField(max_length = 100)
description = models.TextField(max_length = 1000)
uploadfile = models.FileField()
class UploadItemForm(ModelForm):
class Meta:
model = Item
我的模板:
<form enctype="multipart/form-data" method="post" action="/design/">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="upload" />
</form>
如果我上传一些基于文本的文件(大小非常小),一切正常,当上传其他格式或大型csv文件时,代码失败
form = UploadItemForm(request.POST, request.FILES)
nginx说
抱歉,您要查找的页面目前无法使用。请 稍后再试。
我使用的是nginx + uwsgi + django,所以它与uwsgi和nginx设置有关吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
有关其他信息:
client_max_body_size 4M; //4mb
default_type text/plain; //file format
以下是功能列表:http://nginx.org/en/docs/http/ngx_http_core_module.html