尝试简单的图像上传时出现错误:
TypeError at /upload/
__init__() got an unexpected keyword argument 'instance'
以下是相关代码的片段(如果您需要更多,请告诉我!):
# Models
class Photo(models.Model):
created_at = models.DateTimeField(auto_now_add=True, editable=False)
title = models.CharField(max_length=255)
image = models.ImageField(upload_to='photos/'+str(uuid.uuid4())+'/')
# Views
class PhotoUploadView(CreateView):
model = Photo
form_class = PhotoUploadForm
template_name = 'upload.html'
success_url = '/thanks/'
# Forms
class PhotoUploadForm(forms.Form):
image = forms.ImageField()
title = forms.CharField(max_length=255)
# Urls
urlpatterns = patterns('',
url(r'^upload/', views.PhotoUploadView.as_view()),
)