django - 1
Requirement
- virtualenv 설치
pip3 install virtualenv
pip3 install django
pip3 install djangorestframework
- 적용
virtualenv --python=python3 devenv
- window 적용
devenv/Scripts/activate
Create Project
django-admin startproject setting
Secrets
setting.py
에 있는 SECCRET_KEY
는 따로 보관 되어야 됌.
- 보관 파일 생성
touch secrets.json
- 보관
{
"SECRET_KEY": "{SECRET_KEY}"
}
- setting.py 변경
# setting.py
import os
import json
secret_file = os.path.join(BASE_DIR, "secrets.json")
with open(secret_file) as f:
secrets = json.loads(f.read())
def get_secret(setting, secrets=secrets):
try:
return secrets[setting]
except KeyError:
error_msg = f"Set the {setting} environment variable"
raise ImproperlyConfigured(error_msg)
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = get_secret("SECRET_KEY")
Exec
- 기초작업
$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py runserver
- app 생성
django-admin startapp authentication
- python 패키지
pip freeze > requirements.txt
댓글남기기