[수정]
AccountUpdateView, AccountDeleteView 의 context_object_name = 'target_user' 추가pk=user.pk pk=target_user.pk 로 수정path('accounts/', include('accountapp.urls')),
Sign Up Create view
login View
View info Read view
Change info Update view
Quit Delete view
이의 과정들을 거쳐서 Accountapp 을 만들고, Hello World 에 접근하여 아무나 글을 쓸 수 있도록 하였다.
중간에 인증이라는 과정을 넣기 위해서 Accountapp 을 만들었던 것임.
HelloWorld 뿐만 아니라 다른 페이지, (게시글, 게시판 등..) -> 인증 과정이 필요
즉, 이 모든것을 만들어주기 위해 먼저 Accountapp 이라는 것을 먼저 말들어줬던 것이다.

{% if not user.is_authenticated %}# 로그인이 되어있다면 정상적으로 작동
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'))

# views.py
class AccountUpdateView(UpdateView):
...
def get(self, *args, **kwargs):
if self.request.user.is_authenticated: # 로그인이 되어 있다면
return super().get(*args, **kwargs) # 기존의 방식대로 하고
else:
return HttpResponseRedirect(reverse('accountapp:login')) # 로그인 창으로 되돌려 보내기
def post(self, *args, **kwargs):
if self.request.user.is_authenticated: # 로그인이 되어 있다면
return super().get(*args, **kwargs) # 기존의 방식대로 하고
else:
return HttpResponseRedirect(reverse('accountapp:login')) # 로그인 창으로 되돌려 보내기
# DeleteView 에도 추가




from django.http import ... HttpResponseForbidden
...
class AccountUpdateView(UpdateView):
...
def get(self, *args, **kwargs):
if self.request.user.is_authenticated and self.get_object() == self.request.user: # 로그인이 되어 있다면
class AccountDeleteView(DeleteView):
...
def get(self, *args, **kwargs):
...
else:
return HttpResponseForbidden() # 금지된 곳에 접근 했다는 것을 보여주는 것이 Forbidden
#-> else 부분 전부 forbidden 으로 수정
인증 시, 로그인이 되어있어야 하고 그리고
self 는 UpdateView 를 가리키고, 이 안에서 현재 사용되고 있는 객체를 말한다.
get_object() : model : User User 객체 중에서도 UpdateView 같은 경우에는 urls.py 에서 path('update/<int:pk> 처럼 int:pk 를 받는데 이 처럼 그 pk 에 해당하는 object 를 가져오는 것을 의미한다.그 pk 에 해당하는 객체가 지금 request.user (요청하고 있는 사용자)와 같은지 체크
이후 테스트




