-
[Django] Django REST API (1) - 개발환경 설정Phthon/Django 2019. 12. 26. 19:45728x90
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.pyTIME_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.pyDATABASES = {
'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.pyINSTALLED_APPS = [
'rest_framework',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'restful',
]
728x90'Phthon > Django' 카테고리의 다른 글
[Django] REST API (4) - Frontend 연동 (0) 2020.01.01 [Django] Django REST API (3) - REST API CRUD (0) 2019.12.28 [Django] Django REST API (2) - REST API 작성 (0) 2019.12.26 [Django] no migrations to apply 참고 (0) 2019.10.27 [Django] Django HttpResponse list return (0) 2019.09.24