From 646b51e91faf7dc4e476f7c580f1e1f9b7a3dfec Mon Sep 17 00:00:00 2001 From: Lefort Date: Tue, 30 Oct 2018 09:01:23 -0300 Subject: [PATCH 1/2] Add class based login required --- en/authentication_authorization/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/en/authentication_authorization/README.md b/en/authentication_authorization/README.md index bd2b551..523b141 100644 --- a/en/authentication_authorization/README.md +++ b/en/authentication_authorization/README.md @@ -20,6 +20,18 @@ def post_new(request): [...] ``` +Or if you have a class based view: + +```python +from django.views import View + +class MyView(View): + + @method_decorator(login_required) + def get(self, request, *args, **kwargs): + [...] +``` + That's it! Now try to access `http://localhost:8000/post/new/`. Notice the difference? > If you just got the empty form, you are probably still logged in from the chapter on the admin-interface. Go to `http://localhost:8000/admin/logout/` to log out, then go to `http://localhost:8000/post/new` again. From 93a888f7fa48d7e9df58dc3fe032b2ede3793200 Mon Sep 17 00:00:00 2001 From: Lefort Date: Tue, 30 Oct 2018 09:03:20 -0300 Subject: [PATCH 2/2] Import method decorator --- en/authentication_authorization/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/en/authentication_authorization/README.md b/en/authentication_authorization/README.md index 523b141..b67c3a9 100644 --- a/en/authentication_authorization/README.md +++ b/en/authentication_authorization/README.md @@ -24,6 +24,7 @@ Or if you have a class based view: ```python from django.views import View +from django.utils.decorators import method_decorator class MyView(View):