๐ Python/Django CBV(4)
-
Django CBV (3) - DetailView
views.py from django.contrib.auth.models import User from django.views.generic import DetailView class AccountDetailView(DetailView): model = User context_object_name = 'target_user' # target์ด ๋๋ user์ ์ ๋ณด๋ฅผ ๋ณด์ผ ์ ์๋๋ก template_name = "detail.html" User์ detailํ ์ ๋ณด๋ฅผ ๋ณด๊ณ ์ถ์ ๋ DetailView class๋ฅผ ์์ ๋ฐ์ต๋๋ค. model ์ ์ญ์ ๋ฏธ๋ฆฌ ์ ์๋ User ๋ชจ๋ธ์ ๊ฐ์ ธ์ต๋๋ค. context_object_name = 'target_user'๋ ์ง์ ํด์ค์๋ค . ์ด๋ ๊ฒ target_user๋ฅผ ํ ๋นํ..
2021.05.23 -
Django CBV (2) - ๋ก๊ทธ์ธ, ๋ก๊ทธ์์ ๊ตฌํ
Urls.py ์ฒซ์ค์ from django.contrib.auth.views import LogoutView, LoginView ์์ LoginView ์ LogoutView ๋ผ๋ ํด๋์ค๋ฅผ ์์๋ฐ์์์ ํ์ธํ ์ ์์ต๋๋ค. from django.contrib.auth.views import LogoutView, LoginView from django.urls import path from account.views import AccountCreateView, hello_world app_name = "account" urlpatterns = [ path('hello_world', hello_world, name='hello_world'), path('create/', AccountCreateView.as..
2021.05.23 -
Django CBV (1) - ํ์๊ฐ์
FBV(function based view)๊ฐ ์๋ CBV(class based view)๋ก ํ์๊ฐ์ ์ ์์ฑํ๋ฉด, Django๊ฐ ์ ๊ณตํ๋ class๋ฅผ ์์๋ฐ๊ธฐ ๋๋ฌธ์ ๋ ๊ฐ๊ฒฐํ ์ฝ๋๋ก ์์ฑํ ์ ์์ต๋๋ค. Views.py from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User from django.views.generic import CreateView from django.urls import reverse_lazy class AccountCreateView(CreateView): model = User form_class = UserCreationForm success_url = ..
2021.05.23 -
Django Bootstrap4 ์ฐ๋
1. ์ฐ์ Bootstrap ๊ณต์ํํ์ด์ง์์ CSS CDN์ copy ํฉ๋๋ค. https://getbootstrap.com/docs/5.0/getting-started/introduction/ Introduction Get started with Bootstrap, the worldโs most popular framework for building responsive, mobile-first sites, with jsDelivr and a template starter page. getbootstrap.com copy ํ css cdn ์ ์ฅ๊ณ ํ ํ๋ฆฟ ๋ด๋ถ์ ๋ถ์ฌ๋ฃ๊ธฐ ํด์ค๋๋ค. 2. bootstrap4 library๋ฅผ ๋ค์ด๋ก๋ ๋ฐ๊ฒ ์ต๋๋ค. terminal์ pip install django-bootst..
2021.05.23