尝试将图像保存到django中的特定文件夹。我没有得到任何错误,但文件没有出现在它应该的位置。
以下是模型:
class FileUploadHandler(models.Model):
title = models.CharField(max_length=100)
file = models.ImageField(upload_to='/wiki/static/')
查看:
def image_upload(request):
if request.method == 'POST':
form = UploadImageForm(request.POST, request.FILES)
if form.is_valid():
FileUploadHandler(request.FILES['image'])
form.save
return render_to_response('wiki/gallery.html')
else:
form = UploadImageForm()
return render_to_response('wiki/gallery.html', RequestContext(request, {'form': form}))
完全难倒,因为我没有收到错误。
答案 0 :(得分:2)
form.save
结束时使用括号,
即form.save()
答案 1 :(得分:0)
FileUploadHandler.objects.create(file=request.FILES['image'])
https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.create https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files