ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Django] Django REST API (1) - 개발환경 설정
    Phthon/Django 2019. 12. 26. 19:45
    728x90

    0. 가상환경 설정

    python -m venv venv

    venv\Scripts\activate

     

    1. pip 최신버전인지 확인

    python -m pip install --upgrade pip

     

    2. Django 설치

    pip install django~=2.0.0

     

    3. Django 프로젝트 생성

    django-admin.py startproject restStudy .

     

    4. 설정 변경

    restStudy/settings.py

    TIME_ZONE = 'Asia/Seoul'

     

    STATIC_URL = '/static/'

    STATIC_ROOT = os.path.join(BASE_DIR, 'static')

     

    ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']

     

    5. DB 설정

    pip install mysqlclient

    restStudy/settings.py

    DATABASES = {

      'default': {

        'ENGINE': 'django.db.backends.mysql', #use mysql (not sqlite)

        'NAME': 'dbname',

        'USER': 'username',

        'PASSWORD': 'password',

        'HOST': 'localhost',

        'PORT': '3306',

        'OPTIONS': {

          'init_command': 'SET sql_mode="STRICT_TRANS_TABLES"'

        }

      }

    }

     

    INSTALLED_APPS = [

      'django.contrib.admin',

      'django.contrib.auth',

      'django.contrib.contenttypes',

      'django.contrib.sessions',

      'django.contrib.messages',

      'django.contrib.staticfiles',

      'main',

    ]

    python manage.py migrate

     

    모델 생성후

    python manage.py makemigrations main

    python manage.py migrate main

     

     

    5. Main 서버 App 생성

    python manage.py startapp main

     

    6. REST 서버 App 생성

    pip install djangorestframework

    python manage.py startapp restful

    restStudy/settings.py

    INSTALLED_APPS = [

      'rest_framework',

      'django.contrib.admin',

      'django.contrib.auth',

      'django.contrib.contenttypes',

      'django.contrib.sessions',

      'django.contrib.messages',

      'django.contrib.staticfiles',

      'main',

      'restful',

    ]

     

    728x90
Designed by Tistory.