質問

私は検索されるような表現になっていDjango docことはできないようです。私の基本機能の django.contrib.コメント アプリの使用の許可システムの私のwebapp.の節度ある行動が、私を使用しようとしているクラスに基づくビューに基本的な問い合わせのコメントおよび許可のチェックします。 ("EComment"このコンテキスト"の強化により"コメントから継承された基djangoのコメントモデルです。)

の問題なんです comment_id はkwargてい渡されたURLから、urls.py.い取得することにより、適正にクラスに基づくれました。

現在、ベロのエラー TypeError: ModRestore() takes exactly 1 argument (0 given).コード付属します。

urls.py

url(r'restore/(?P<comment_id>.+)/$', ModRestore(), name='ecomments_restore'),

views.py

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()
役に立ちましたか?

解決

あなたは、クラスベースのビューを使用していません。あなたは誤って代わりにdefclassを書いてます:

def ECommentModerationApiView(object):
...
def ModRestore(ECommentModerationApiView):

おそらくする必要があります:

class ECommentModerationApiView(object):
...
class ModRestore(ECommentModerationApiView):

他のヒント

また、見えるようにあなたのURLパターンのニーズます:

url(r'restore/(?P<comment_id>.+)/$', ModRestore.as_view(), name='ecomments_restore'),
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top