2012-12-19 11 views
7

に異なるHTTPメソッドを飾るためにどのように、私はGETとPOSTの両方、今例えば、単一のクラスベースのビュー

class ViewOne(View): 
    def post(self, request, *args, **kwargs): 
     ... 
    def get(self, request, *args, **kwargs): 
     ... 
    @method_decorator(login_required) 
    def dispatch(self, *args, **kwargs): 
     return super(ViewOne, self).dispatch(*args, **kwargs) 

、以下のように、GETとPOSTメソッドの両方ができますクラスベースのビューを持っているがlogin_requiredています。しかし、POSTだけをlogin_requiredにしたいのですが?

答えて

4

hm ...動作しませんか?

class ViewOne(View): 
    @method_decorator(login_required) 
    def post(self, request, *args, **kwargs): 
     ... 
    def get(self, request, *args, **kwargs): 
     ...  
+0

作品フム、!ありがとう〜 – yejinxin

1

なぜもdjango-bracesを使用し、2つのクラスを作成しません。)

class ViewOne(View): 
    def get(self, request, *args, **kwargs): 
    ... 

class ViewTwo(LoginRequiredMixin, ViewOne): 
    def post(self, request, *args, **kwargs): 
    ... 
関連する問題