我知道错误发生在哪里,但不知道为什么以及如何解决这个错误。我的意思是,我知道错误意味着什么但不知道为什么我的代码会导致错误。这是我的代码
class PostCreateView(CreateView):
model = Post
form_class = PostForm
template_name = 'main/add_post.html'
def form_valid(self, form):
self.object = form.save(commit=False)
# any manual settings go here
self.object.moderator = self.request.user
self.object.image = extract(self.object.url)
self.object.save()
return HttpResponseRedirect(reverse('post', args=[self.object.slug]))
def get_context_data(self, **kwargs):
context = super(PostCreateView, self).get_context_data(**kwargs)
post = self.model.objects.get(pk=kwargs.get('pk'))
options = {'size': (64, 64), 'crop': True}
context['post_thumbnail'] = get_thumbnailer(post.image).get_thumbnail(options).url
return context
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(PostCreateView, self).dispatch(request, *args, **kwargs)
此行发生错误
post = self.model.objects.get(pk=kwargs.get('pk'))
我不明白,因为我从其中一个帖子发帖。我只是得到那篇文章的图像。