반응형
CodingEntrepreneurs Django 강의 정리
APP 생성>
python manage.py startapp appname
settings>
# Application definition
INSTALLED_APPS = [ # components
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
INSTALLED_APPS += [
"blog",
]
app을 생성하고 settings - INSTALLED_APPS에 추가 해준다.
명시적으로 하기 위하여 위와 같이 사용하는 것을 추천한다.
makemigrations>
python manage.py makemigrations appname
1. 모델을 변경시킨 사실과 변경사항을 migration으로 저장
migrate>
python manage.py migrate appname
1. 데이터베이스 상태를 현재 모델 및 마이그레이션 집합과 동기화한다.
주의사항>
1. app을 추가하면 반드시 settings에 추가한다.
2. app에 models를 수정 하면 makemigrations + migrat 를 진행한다.
settings>
"""
Django settings for try_django project.
Generated by 'django-admin startproject' using Django 3.0.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "b#eg47l(0%=d!3uao3xgs68q)_zz+65d4okbfnxsdk-ig$4n9&"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [ # components
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
INSTALLED_APPS += [
"blog",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "try_django.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(BASE_DIR, "templates")
], # 'D:\Code\Study\Try_DJANGO_TUTORIAL_Ver2.2\templates'
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "try_django.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = "/static/"
models>
from django.db import models
# Create your models here.
class BlogPost(models.Model):
title = models.TextField()
content = models.TextField(null=True, blank=True)
반응형
'Python_WEB > Try_Django' 카테고리의 다른 글
[Django]Model to Django Admin (0) | 2020.06.14 |
---|---|
[Django]Save to the Database (0) | 2020.06.14 |
[Django]Built-In Template Tags (0) | 2020.06.14 |
[Django]Template Context Processors (0) | 2020.06.14 |
[Django]Rendering Any Kind of Template (0) | 2020.06.14 |