Django中的图片上传,名称错误

时间:2014-06-26 16:44:48

标签: python django image file-upload

获取NameError(未定义全局名称FileUploadHandler)。这是模型:

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'])
            return render_to_response('wiki/gallery.html')
    else:
        form = UploadImageForm()
     return render_to_response('wiki/gallery.html', RequestContext(request, {'form': form}))

我错过了什么?

1 个答案:

答案 0 :(得分:0)

在视图文件的顶部,输入:

from models import FileUploadHandler

这假设您具有标准views.pymodels.py文件结构,两者都在同一目录中。