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

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

๋ชฉ์ฐจ

  1. ๋“ค์–ด๊ฐ€๊ธฐ์ „
  2. ํŒŒ์ผ ๊ด€๋ฆฌ ์ ์šฉํ•˜๊ธฐ
  3. Result

0. ๋“ค์–ด๊ฐ€๊ธฐ์ „

  • ์ ์šฉํ•  ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ์„ฑ์ด ๋˜์–ด ์žˆ์–ด์•ผํ•จ. (๋ณธ ํฌ์ŠคํŒ…์—์„œ๋Š”๊ณ„์ •๊ด€๋ฆฌ์‹œ์Šคํ…œ์„ ์ ์šฉํ•  ํ”„๋กœ์ ํŠธ๋ฅผ myproject ๋ผ๊ณ  ์ง€์นญํ•จ)

  • โš ๏ธ โ—๏ธโ—๏ธโ—๏ธโ—๏ธ ๋ณธ ํฌ์ŠคํŒ…์—์„œ ์‹คํ–‰ํ•˜๋Š” Terminal ๊ฒฝ๋กœ๋Š” ๋ชจ๋‘ Project ๋‚ด ์œ„์น˜์ž„(manage.py ๊ฐ€ ์žˆ๋Š” ๊ฒฝ๋กœ) โ—๏ธโ—๏ธโ—๏ธโ—๏ธ

    myproject 
    |- myproject
    |- manage.py   <--- 
    	... 
    
  • git clone (terminal)

    git clone https://[email protected]/pai-seocho/django-tutorial
    
  • ํ™˜๊ฒฝ ๊ตฌ์„ฑ (terminal)

    cp django-tutorial/fms/requirements.txt ./
    pip install -r requirements.txt
    
  • app ํด๋” ์ด๋™ (terminal)

    mv django-tutorial/fms/file ./
    mv django-tutorial/fms/templates ./
    mv django-tutorial/fms/helper.py ./
    rm -rf  django-tutorial 
    

1. ํŒŒ์ผ ๊ด€๋ฆฌ ์ ์šฉํ•˜๊ธฐ

1.1 App ๋“ฑ๋ก ๋ฐ Setting ์„ค์ • ์ถ”๊ฐ€

  • ์ถ”๊ฐ€๋œ ์ฝ”๋“œ ๋ถ€๋ถ„๋งŒ ๊ธฐ์กด ์ฝ”๋“œ์— ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค(python)

    # myproject/settings.py
    INSTALLED_APPS = [
    		...
        'file',  # <-- ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
    ]
    
    TEMPLATES = [
      { ...
      'DIRS': [os.path.join(BASE_DIR, 'templates')], # <-- ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
      ...}]
    
    MEDIA_ROOT = BASE_DIR / 'media'  # <-- ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
    MEDIA_URL = '/media/' # <-- ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
    
    
  • Migrations (terminal)

    python manage.py makemigrations
    python manage.py migrate --run-sync
    
  • URLConf ๋“ฑ๋ก (python)

    # myproject/urls.py
    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('file/', include('file.urls'), name='file'), # <-- ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
    ]
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)  # <-- ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
    

2. Result

2.1 Create

create

2.2 Read

read