728x90
반응형
views.py
class AccountDeleteView(DeleteView):
model = User
success_url = reverse_lazy('accountapp:login')
template_name = 'accountapp/delete.html'
urls.py
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import path
from accountapp.views import hello_world, AccountCreateView, AccountDetailView, AccountUpdateView, AccountDeleteView
app_name = 'accountapp'
urlpatterns = [
path('hello_world/', hello_world, name='hello_world'),
path('login/', LoginView.as_view(template_name='accountapp/login.html'), name='login'),
path('logout/', LogoutView.as_view(), name='logout'),
path('create/', AccountCreateView.as_view(), name='create'),
path('detail/<int:pk>', AccountDetailView.as_view(), name='detail'),
path('update/<int:pk>', AccountUpdateView.as_view(), name='update'),
path('delete/<int:pk>', AccountDeleteView.as_view(), name='delete'),
]
delete.html
{% extends 'base.html'%}
{% load bootstrap4 %}
{% block content %}
<div style="text-align: center; max-width: 500px; margin: 4rem auto">
<div class="mb-4">
<h4>Quit</h4>
</div>
<form action="{% url 'accountapp:delete' pk=user.pk %}" method="post">
{% csrf_token %}
<input type="submit" class="btn btn-dark rounded-pill col-6 mt-3">
</form>
</div>
{% endblock %}
detail.html
{% extends 'base.html' %}
{% block content %}
<div>
<div style="text-align: center; max-width: 500px; margin: 4rem auto;">
<p>
{{ target_user.date_joined }}
</p>
<h2 style="font-family: 'NanumSquareB'">
{{ target_user.username}}
</h2>
{% if target_user == user %}
<a href="{% url 'accountapp:update' pk=user.pk %}">
<p>
Change Info
</p>
</a>
<a href="{% url 'accountapp:delete' pk=user.pk %}">
<p>
Quit
</p>
</a>
{% endif %}
</div>
</div>
{% endblock %}
728x90
반응형
'웹 프로그래밍' 카테고리의 다른 글
[pinterest clone (20)] Authentication (0) | 2021.04.28 |
---|---|
[pinterest clone (19)] Bug fix (0) | 2021.04.28 |
[pinterest clone (17)] UpdateView를 이용한 비밀번호 변경 구현 (0) | 2021.04.28 |
[pinterest clone (16)] DetailView를 이용한 개인페이지 구현 (0) | 2021.04.28 |
[pinterest clone (15)] form 디자인 (0) | 2021.04.28 |