로그인된 사용자만 이용가능
from django.shortcuts import redirect
def login_required(fn):
def wrapper_fn(request, *args, **kwargs):
admin_id = request.session.get('admin', None)
if admin_id is None:
return redirect("http://127.0.0.1:8000")
return fn(request, *args, **kwargs)
return wrapper_fn
@method_decorator(login_required, name="dispatch")
class HomeView(View):
def get(self, request, *args, **kwargs):
- login view ( post, delete 요청 > 로그인, 로그아웃)
def post(self, request):
...
..
.
request.session["admin"] = admin_id
def delete(self, request):
if request.session.get('admin'):
del(request.session['admin'])