Skip to content

Instantly share code, notes, and snippets.

@patrys
Created December 20, 2016 22:22
Show Gist options
  • Select an option

  • Save patrys/d65a5daceb7417d69b61ae10509ecf70 to your computer and use it in GitHub Desktop.

Select an option

Save patrys/d65a5daceb7417d69b61ae10509ecf70 to your computer and use it in GitHub Desktop.

Revisions

  1. patrys created this gist Dec 20, 2016.
    12 changes: 12 additions & 0 deletions cbv-decorator1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    from django.contrib.auth.decorators import login_required
    from django.template.response import TemplateResponse
    from django.utils.decorators import method_decorator
    from django.views.generic import View

    class MyClassBasedView(View):
    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
    return super().dispatch(*args, **kwargs)

    def get(self, request):
    return TemplateResponse(request, 'index.html')