获取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}))
我错过了什么?
答案 0 :(得分:0)
在视图文件的顶部,输入:
from models import FileUploadHandler
这假设您具有标准views.py
和models.py
文件结构,两者都在同一目录中。