Djangoのインストールと設定


設定

python -m venv venv
source venv/bin/activate
pip install django

django-admin startproject mysite .
python manage.py startapp api

python manage.py makemigrations
python manage.py migrate
python manage.py runserver

pip freeze > requirements.txt
pip install -r requirements.txt

設定

# /mysite/config.py
CONFIG = {
    "SECRET_KEY": 'Your Secret Key'
}
# /mysite/settings.py

# SECURITY WARNING: keep the secret key used in production secret!
from mysite.config import CONFIG
SECRET_KEY = CONFIG["SECRET_KEY"]

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db' / 'db.sqlite3',
    }
}

# Html files
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [ 'build/' ],
		},
]

# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Seoul'
USE_I18N = True
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'build/static/'
STATICFILES_DIRS = [
    BASE_DIR / "build/static",
]