implementing account management system - pai-plznw4me/django-initializer GitHub Wiki

๊ณ„์ • ๊ด€๋ฆฌ ์‹œ์Šคํ…œ ์ ์šฉํ•˜๊ธฐ

๋ชฉ์ฐจ

  1. ๋“ค์–ด๊ฐ€๊ธฐ์ „
  2. ๊ณ„์ • ๊ด€๋ฆฌ ์ ์šฉํ•˜๊ธฐ
    1. Git clone
    2. ํ™˜๊ฒฝ ๊ตฌ์„ฑ
    3. App ๋“ฑ๋ก ๋ฐ Setting ์„ค์ • ์ถ”๊ฐ€
  3. Result
    1. Signup
    2. Login
    3. Profile
    4. admin

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

2.4 admin