For example, I have a class based view which allows both GET and POST method, as below,
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)
Now, both GET and POST are login_required. But what if I want only POST to be login_required?
Hm... Is it not working?
class ViewOne(View):
@method_decorator(login_required)
def post(self, request, *args, **kwargs):
...
def get(self, request, *args, **kwargs):
...
Why don't create two classes, use also django-braces ;)
class ViewOne(View):
def get(self, request, *args, **kwargs):
...
class ViewTwo(LoginRequiredMixin, ViewOne):
def post(self, request, *args, **kwargs):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With