PROJECTS

Django | ์žฅ๊ณ ์˜ ๊ธฐ๋ณธ ์ œ๊ณต User๋ชจ๋ธ์ด ์•„๋‹Œ ์‚ฌ์šฉ์ž ์ง€์ • ๋ชจ๋ธ ์‚ฌ์šฉํ•˜๊ธฐ

nicesugi 2022. 5. 30. 13:17

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป Github

https://github.com/nicesugi/DjangoClass/tree/main/django/sns

 

Added upgrade user app > migrate

Refactor : AUTH_USER_MODEL = 'user.UserModel' & function sign_up_view

Refactor : function sign_in_view


 

์ฐธ๊ณ ํ•˜์„ธ์šฉ. django doc - customizing

https://docs.djangoproject.com/en/4.0/topics/auth/customizing/

 

Customizing authentication in Django | Django documentation | Django

Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate

docs.djangoproject.com


๐ŸŒฑ User ๋ชจ๋ธ ๋Œ€์ฒดํ•˜๊ธฐ

์žฅ๊ณ ์—์„œ ์ œ๊ณต๋˜๋Š” ๊ธฐ๋ณธ ์ธ์ฆ๊ณผ์ •์„ user์•ฑ์— ์ž‘์„ฑํ•œ UserModel๋กœ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๋œป

AUTH_USER_MODEL: ๊ธฐ๋ณธ ์ธ์ฆ ๊ณผ์ •

mySpartaSns/settings.py

AUTH_USER_MODEL

 

๐ŸŒฑ ์‚ฌ์šฉ์ž ์ •์˜ ์‚ฌ์šฉ์ž ๋ชจ๋ธ ์‚ฌ์šฉํ•˜๊ธฐ

์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ ์žฅ๊ณ  ๊ธฐ๋ณธ User๋ชจ๋ธ์ด ์ถฉ๋ถ„ํ•˜๋”๋ผ๋„ ์‚ฌ์šฉ์ž ์ง€์ • ์‚ฌ์šฉ์ž ๋ชจ๋ธ์„ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค๊ณ  ํ•œ๋‹ค

์ž‘๋™์€ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ๋ชจ๋ธ๊ณผ ๋™์ผํ•˜๋‹ค

๋จผ์ € settings.py์—์„œ AUTH_USER_MODEL ๋ฅผ ๋จผ์ € ์ •์˜ํ•ด์ฃผ์–ด์•ผ ํ•˜๋ฉฐ,

๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์„ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ์ฒ˜์Œ์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ '์ „'์— ์ž‘์—…ํ•ด์ฃผ์ž.

(๋ธ”๋กœ๊ทธ ์ˆœ์„œ๋Œ€๋กœ ํ•ด์ฃผ์‹œ๋ฉด ๋˜์šฉ)

user/models.py

AbstractUser ์ž„ํฌํŠธ

 

๐ŸŒฑ ์•ฑ ๋ชจ๋ธ ๋“ฑ๋ก

user/admin.py

admin์— ์‚ฌ์šฉ์ž ์ง€์ •๋ชจ๋ธ ๋“ฑ๋ก

 

๐ŸŒฑ ๋ณ€๊ฒฝ๋œ ๋‚ด์šฉ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ์šฉ

์ˆœ์„œ๋ฅผ ๊ผญ ์ง€์ผœ์ฃผ์ž

๋จผ์ € ์ง€์ •๋ชจ๋ธ์„ ์ •์˜ > ์‚ฌ์šฉ(์ž„ํฌํŠธ) > ์–ด๋“œ๋ฏผ ๋“ฑ๋ก > ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ์šฉ

ํ„ฐ๋ฏธ๋„์„ ์ผœ์„œ Applying user(๋ชจ๋ธ ์ง€์ •ํ•ด์ค€ ๊ณณ)OK ๋ฅผ ํ™•์ธ

python manage.py makemigrations
python manage.py migrate

python manage.py makemigrations / python manage.py migrate

 

๐ŸŒฑ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ™•์ธ

VSCode์—์„œ SQLite ๊ฐ€ ์—†์–ด์ง€๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์„ํ…๋ฐ, โŒ˜+โ‡ง+P๋ฅผ ๋ˆ„๋ฅด๋ฉด ์ธํ„ฐํ”„๋ฆฌํ„ฐ ์„ค์ • ์œ„์— sql์ด ์ƒ๊ธฐ๋Š”๋ฐ

ํŒŒ์ผ์ด ์žˆ๋Š” ๊ฒฝ๋กœ๋ฅผ ํ™•์ธํ•ด์„œ ๋”๋ธ”ํด๋ฆญํ•˜๋ฉด ์™ผ์ชฝ ํ•˜๋‹จ์— ์ƒ๊ธด๋‹ค.

 

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ์‚ด์ง ๋ฐ”๋€๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค. before๋Š” ๋”ฐ๋กœ ์บก์ณํ•˜์ง€ ์•Š์Œ. ์ด์ „ ํฌ์ŠคํŒ… ํ™•์ธํ•ด์ฃผ์„ธ์š”.

Sqlite ํ™•์ธ

 

๐ŸŒฑ User/views.py 

ํšŒ์›๊ฐ€์ž…/๋กœ๊ทธ์ธ์— ํ•ด๋‹นํ•˜๋Š” ์ž„ํฌํŠธ๋ฅผ contrib๋ฅผ ์‚ฌ์šฉํ•ด user๋ชจ๋ธ์„ ํ™•์žฅ

๊ฐ 1๋ฒˆ ์ฝ”๋“œ๋Š” user/views.py ์œ—๋ถ€๋ถ„์— ๊ฐ™์ด ์กด์žฌํ•œ๋‹ค(ํ•˜๋‚˜๋งŒ ํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๊ณ  ์ž„ํฌํŠธ๊ฐ€ ์ค‘๊ฐ„์— ์ƒ๊ฒจ์„œ๋„ ์•ˆ๋จ)

๊ธฐ์กด User๋ชจ๋ธ ํ™•์žฅ
๊ธฐ์กด User๋ชจ๋ธ ํ™•์žฅ

 

 

 

 

 

๋ฐ˜์‘ํ˜•