๐Ÿงฉ DJANGO

alsk9624ยท2024๋…„ 8์›” 21์ผ
0
  • Django ๊ธฐ๋ณธ User ๋ชจ๋ธ ๊ฐœ์š”
    : Django์˜ ๊ธฐ๋ณธ User ๋ชจ๋ธ์€ django.contrib.auth.models ๋ชจ๋“ˆ์— ์ •์˜

  • User ๋ชจ๋ธ ์ž„ํฌํŠธ ๋ฐ ์‚ฌ์šฉ
    : Django์˜ ๊ธฐ๋ณธ User ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ํ•ด๋‹น ๋ชจ๋ธ์„ ์ž„ํฌํŠธํ•˜์—ฌ ์ ‘๊ทผ ๊ฐ€๋Šฅ

from django.contrib.auth.models import User
  • ์‚ฌ์šฉ์ž ์ƒ์„ฑ
    - ๊ด€๋ฆฌ์ž ๊ณ„์ • ์ƒ์„ฑํ•˜๋Š” ๋ฒ•
python manage.py createsuperuser
  • ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ ์œผ๋กœ ์‚ฌ์šฉ์ž ์ƒ์„ฑํ•˜๋Š” ๋ฒ•
from django.contrib.auth.models import User

# ์ƒˆ๋กœ์šด ์‚ฌ์šฉ์ž ์ƒ์„ฑ
user = User.objects.create_user(
    username='john_doe',
    email='john@example.com',
    password='securepassword123'
)
# ์Šˆํผ ์œ ์ € ์ƒ์„ฑํ•˜๊ธฐ
superuser = User.objects.create_superuser(
    username='admin',
    email='admin@example.com',
    password='adminpassword123'
)
  • create_ ๋งค์„œ๋“œ
    • create_user ๋ฉ”์„œ๋“œ๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ•ด์‹œํ™”ํ•˜์—ฌ ์ €์žฅํ•˜๋ฏ€๋กœ, ์ง์ ‘ User ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์•ˆ์ „
    • ์Šˆํผ์œ ์ €๋ฅผ ์ƒ์„ฑํ•˜๋ ค๋ฉด create_superuser ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉ
    • ์ด๋ ‡๊ฒŒ ์ƒ์„ฑ๋œ ์Šˆํผ์œ ์ €๋Š” ๋ชจ๋“  ๊ถŒํ•œ์„ ๊ฐ€์ง€๋ฉฐ, ๊ด€๋ฆฌ์ž ์‚ฌ์ดํŠธ์— ์ ‘๊ทผ ๊ฐ€๋Šฅ
  • ์ปค์Šคํ…€ ๋ชจ๋ธ ํ™•์žฅ์€ settings.py์— ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ๋ชจ๋ธ๋กœ ์ง€์ •ํ•ด์•ผ ๋จ
profile
์•ž๊ธธ์— ๋Ÿญํ‚คโ˜…๋น„ํ‚ค๋งŒ ์žˆ๊ธธ ,,,๐Ÿ€๐Ÿซง

0๊ฐœ์˜ ๋Œ“๊ธ€