implementing account management system - pai-plznw4me/django-initializer GitHub Wiki
๊ณ์ ๊ด๋ฆฌ ์์คํ ์ ์ฉํ๊ธฐ
๋ชฉ์ฐจ
0. ๋ค์ด๊ฐ๊ธฐ์
0. ๋ค์ด๊ฐ๊ธฐ์ | 1. ๊ณ์ ๊ด๋ฆฌ ์ ์ฉํ๊ธฐ | 2.Result
- ์ ์ฉํ ํ๋ก์ ํธ ์์ฑ
(๋ณธ ํฌ์คํ
์์๋
๊ณ์ ๊ด๋ฆฌ์์คํ
์ ์ ์ฉํ ํ๋ก์ ํธ๋ฅผmyproject
๋ผ๊ณ ์ง์นญํจ)
1. ๊ณ์ ๊ด๋ฆฌ ์ ์ฉํ๊ธฐ
0. ๋ค์ด๊ฐ๊ธฐ์ | 1. ๊ณ์ ๊ด๋ฆฌ ์ ์ฉํ๊ธฐ | 2.Result
-
๋ณธ ํฌ์คํ ์์๋
๊ณ์ ๊ด๋ฆฌ์์คํ
์ ์ ์ฉํ ํ๋ก์ ํธ๋ฅผmyproject
๋ผ๊ณ ์ง์นญํจ -
โ ๏ธ โ๏ธ ๋ณธ ํฌ์คํ ์์ ์คํํ๋ Shell ๊ฒฝ๋ก๋ ๋ชจ๋
Project
๋ด ์์น์ -
Anaconda ๊ฐ ์ค์น๋์ด์ผ ํจ
1.1 Git clone
git clone https://{token}@github.com/pai-seocho/django-tutorial
โ checkpoint
-
git clone ํ ํด๋๊ตฌ์กฐ ์๋์ ๊ฐ์์ผ ํจ
myproject |- django-tutorial |-ams ...
1.2 ํ๊ฒฝ ๊ตฌ์ฑ
cp django-tutorial/ams/requirements.txt ./
conda create --name {myenv} python=3.8 -y
conda activate {myenv}
1.3 App ๋ฑ๋ก ๋ฐ Setting ์ค์ ์ถ๊ฐ
-
myproject/django-tutorial/ams/account
ํด๋น ํด๋์ ์๋ App ์ my_project ํด๋๋ก ์ด๋ํ๋ค. -
myproject/django-tutorial/helper.py
ํ์ผ์ my_project ํด๋๋ก ์ด๋ํ๋ค. ๊ทธ ์ด์ธ์ ํ์ผ์ ํ์ ์์ผ๋ ์ญ์ ํ๋ค.mv django-tutorial/ams/account ./ mv django-tutorial/helper.py ./
rm -rf django-tutorial
-
APP
๋ฑ๋ก ๋ฐ์ปค์คํฐ๋ง์ด์ง ์ ์
๋ชจ๋ธ# myproject/settings.py INSTALLED_APPS = [ 'django.contrib.admin', ... 'account', # <-- ์ถ๊ฐ๋ ์ฝ๋ ] AUTH_USER_MODEL = 'account.CustomUser' # <-- ์ถ๊ฐ๋ ์ฝ๋ MEDIA_ROOT = BASE_DIR / 'media' # <-- ์ถ๊ฐ๋ ์ฝ๋ MEDIA_URL = '/media/' # <-- ์ถ๊ฐ๋ ์ฝ๋ LOGIN_REDIRECT_URL = '/account/profile' # <-- ์ถ๊ฐ๋ ์ฝ๋
-
Migrations
python manage.py makemigrations python manage.py migrate --run-sync
-
URLConf ๋ฑ๋ก
from django.urls import path, include # <-- ์ถ๊ฐ๋ ์ฝ๋ from django.conf.urls.static import static # <-- ์ถ๊ฐ๋ ์ฝ๋ from myproject import settings # <-- ์ถ๊ฐ๋ ์ฝ๋ # myproject/urls.py urlpatterns = [ path('admin/', admin.site.urls), path('account/', include('account.urls'), name='account'), # <-- ์ถ๊ฐ๋ ์ฝ๋ path('account/', include('django.contrib.auth.urls')), # <-- ์ถ๊ฐ๋ ์ฝ๋ ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # <-- ์ถ๊ฐ๋ ์ฝ๋
-
LoginView ๋ณ๊ฒฝ
# from django.contrib.auth.views import LoginView class LoginView(RedirectURLMixin, FormView): """ Display the login form and handle the login action. """ ... template_name = "account/login.html" #<-- ๋ณ๊ฒฝ๋ ๋ถ๋ถ
-
create admin(superuser) user
python manage.py shell
from account.helper import createsuperuser createsuperuser() exit()
โ Checkpoint :
'Create Superuser : admin '
2. Result
0. ๋ค์ด๊ฐ๊ธฐ์ | 1. ๊ณ์ ๊ด๋ฆฌ ์ ์ฉํ๊ธฐ | 2.Result
2.1 Signup
2.2 Login
2.3 Profile
- http://localhost:8000/account/profile/ (โ ๏ธ login ์ด ๋จผ์ ๋์ด์ผ ํ๋ค.)