📢 공지사항
home

Authentication 인증시스템 구축

수강계획
2022/01/11
번호
27
복습여부
수강여부
수강일
2022/01/12
속성
hello_world로 들어가도 로그인 안되어있다면 로그인 창으로 보내기
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render # Create your views here. from django.urls import reverse, reverse_lazy from django.views.generic import CreateView, DetailView, UpdateView, DeleteView from accountapp.forms import AccountUpdateForm from accountapp.models import HelloWorld 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() hello_world_list = HelloWorld.objects.all() 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')) class AccountCreateView(CreateView): model = User form_class = UserCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'accountapp/create.html' class AccountDetailView(DetailView): model = User context_object_name = 'target_user' template_name = 'accountapp/detail.html' class AccountUpdateView(UpdateView): model = User context_object_name = 'target_user' form_class = AccountUpdateForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'accountapp/update.html' class AccountDeleteView(DeleteView): model = User context_object_name = 'target_user' success_url = reverse_lazy('accountapp:login') template_name = 'accountapp/delete.html'
Python
복사
views.py 템플릿도 target_user로 수정하기!
from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('accountapp.urls')),
Python
복사
jichuuu.urls.py
계정 정보 수정하는 페이지도 로그인 안된 상태에서 수정할 수 있으면 안됨
다른 사람 계정 탈퇴시킬 수 있다 ,,!