我正在上传图片,但它不起作用的功能是:在视图中
def upload_file(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['file'])
return HttpResponseRedirect('/user_profileform/')
else:
form = UploadFileForm()
return render_to_response('user_profile.html', {'form': form })
def handle_uploaded_file(f):
with open('ranjeet.txt', 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
form is:
<form action="" method="POST" enctype="multipart/form-data" name="uform" id="userform">{% csrf_token %}
{{form}}
<input type="submit" value="submit" name="usubmit">
</form>
在设置中:
MEDIA_ROOT = '/media/images/' MEDIA_URL = '/media/'
我不知道文件保存在哪里。