我搜了搜so和django医生,似乎找不到这个。我正在扩展
django.contrib.comments公司
应用程序以使用我的webapp中的自定义权限系统。对于审核操作,我试图使用基于类的视图来处理注释的基本查询和对它的权限检查。
(本文中的“ecomment”是我的“增强注释”,继承自基本django注释模型。)
我的问题是
comment_id
是从url.py中的url传入的Kwarg。如何从基于类的视图中正确地检索它?
现在,Django正在抛出错误
TypeError: ModRestore() takes exactly 1 argument (0 given)
. 代码如下。
URLS.Py
url(r'restore/(?P<comment_id>.+)/$', ModRestore(), name='ecomments_restore'),
VIEW
def ECommentModerationApiView(object):
def comment_action(self, request, comment):
"""
Called when the comment is present and the user is allowed to moderate.
"""
raise NotImplementedError
def __call__(self, request, comment_id):
c = get_object_or_404(EComment, id=comment_id)
if c.can_moderate(request.user):
comment_action(request, c)
return HttpResponse()
else:
raise PermissionDenied
def ModRestore(ECommentModerationApiView):
def comment_action(self, request, comment):
comment.is_removed = False
comment.save()