我是 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")
模型.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的设置有关系吗?