【发布时间】:2015-06-06 02:23:00
【问题描述】:
我想验证更新帖子的用户是帖子的作者。
我的代码如下所示(相关部分):
class UpdatePostView(UpdateView):
model = Post
fields = ['body']
template_name = 'forum/post_update_form.html'
def dispatch(self, *args, **kwargs):
if self.request.user != self.object.author:
return HttpResponseForbidden()
return super(CreatePostView, self).dispatch(*args, **kwargs)
我得到的错误:
'UpdatePostView' object has no attribute 'object'
在这一点上,我有点困惑,因为文档说:When using UpdateView you have access to self.object, which is the object being updated.
我错过了什么?
【问题讨论】:
标签: python django django-views