본문 바로가기
기타/django

작정하고 장고 - Authentication 인증시스템 구축

by 방배킹 2023. 5. 15.

오류 수정

accountapp의 urls.py에서 AccountUpdateView(UpdateView)와 AccountDeleteView(DeleteView)에
context_object_name = 'target_user'를 추가해준뒤
update.html과 delete.html에 user를 targer_user로 변경해준다.

27강 Authentication 인증시스템 구축


로그인 하지 않고 hello_world로 이동을 하고


2번 계정으로 로그인을 한뒤


1번 계정 삭제 페이지로 이동 할수있다.

이런 문제를 해결하기 위해 우선

def hello_world(request):

    if request.user.is_authenticated:
        if request.method == "POST":

            temp = request.POST.get('hello_world_input')

            new_hello_world = helloWorld()
            new_hello_world.text = temp
            new_hello_world.save()

            return HttpResponseRedirect(reverse('accountapp:hello_world'))

        else:
            hello_world_list = helloWorld.objects.all()
            return render(request, 'accountapp/hello_world.html', context={'hello_world_list': hello_world_list})
    else:
        return HttpResponseRedirect(reverse('accountapp:login'))

if request.user.is_authenticated:를 추가해서 is_authenticated하면 접속이 가능하고
그렇지 않으면 login.html로 보낸다.

댓글