*์ฅ๊ณ ์ค์นํ๊ธฐ
* pip install django ๋ฅผ ์
๋ ฅํด ์ฅ๊ณ ๋ฅผ ์ค์นํด์ค๋๋ค.
์ฅ๊ณ ๊ฐ ์ค์น๋๋ฉด, django-admin ์ผ๋ก ์์๋๋ ๋ช
๋ น์ ํ ์ ์์ต๋๋ค. ์ผ๋จ ๊ฐ์ฅ๋จผ์ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด์ค์ผ ํฉ๋๋ค.
*ํ๋ก์ ํธ ์์ฑํ๊ธฐ
*django-admin startproject "ํ๋ก์ ํธ ์ด๋ฆ"
์
๋ ฅ์ ํ๊ณ ๋๋ฉด , ํด๋๊ฐ ์๊ธฐ๊ณ , ์์ ์ฌ๋ฌ๊ฐ์ง ํ์ด์ฌ ํ์ผ์ด ์๊น๋๋ค. (์ฅ๊ณ ๋ผ๋ ํ๋ ์์ํฌ๊ฐ ํ๋ก์ ํธ์ ๊ตฌ์ฑ์์๋ฅผ ๋ง๋ค์ด์ค๋๋ค.)
์ ๋ django-admin startproject new_1 ์ผ๋ก ํ๊ธฐ๋๋ฌธ์ new_1์ด๋ผ๋ ํด๋๊ฐ ์๊ฒผ์ต๋๋ค.
๋ค์์ ํ๋ก์ ํธ ์์ ๊ตฌ์ฑํด์ค app ์ ์์ฑํฉ๋๋ค.
*app ์์ฑํ๊ธฐ
*django-admin startapp "์ฑ ์ด๋ฆ"
๋ง์ฐฌ๊ฐ์ง๋ก ์ฑ์ ์์ฑํ๋ฉด ํด๋๊ฐ ์๊น๋๋ค. ์ ๋ user ๋ผ๋ ์ฑ์ ๋ง๋ค์์ต๋๋ค.
๋ช๊ฐ์ง ํด๋์ ํ์ด์ฌ ํ์ผ๋ค์ด ์๊ฒผ์ต๋๋ค. ์ด๋ ๋์ค์ ์ฌ์ฉํ htmlํ์ผ์ ๋ฃ๊ธฐ ์ํ "templates"๋ผ๋ ํด๋๋ฅผ ๋ง๋ค์ด ์ค์ผ ํฉ๋๋ค. ์์ ํ์ด์ง๋ฅผ ๊ตฌ์ฑํ htmlํ์ผ์ ๋ฃ๊ณ , ์ฅ๊ณ ์์ ์ด๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํจ์
๋๋ค.
*์ฑ ๋ฑ๋กํ๊ธฐ
๋ง์ง๋ง์ผ๋ก ์ฑ์ ๋ง๋ค์์ผ๋ฏ๋ก ๋ฑ๋กํด์ฃผ์ด์ผ ํฉ๋๋ค.
ํ๋ก์ ํธ ํด๋ - ํ๋ก์ ํธ๋ช
๊ณผ ๊ฐ์์ด๋ฆ์ ํด๋ - settings.py ์ ๋ค์ด๊ฐ๋๋ค.
*setting.py
"""
Django settings for new_1 project.
Generated by 'django-admin startproject' using Django 3.0.1.
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 = '=2gx!y#c)ht56tyv_5a4-1iq8of3d526y5r3pe8g)pu^^i_gqe'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
##############์ด๊ณณ์ ์์ฑํ ์ฑ ์ด๋ฆ์ ์ ์ด์ฃผ์ด์ผ ํฉ๋๋ค
'user'
]
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 = 'new_1.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'new_1.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/'
40๋ฒ์งธ ์ค์ฏค, INSTALLED_APPS = ์์ ์์ ์ด ์์ฑํ App ์ด๋ฆ์ ์ ์ผ๋ฉด ์ฌ์ฉํ ์ค๋น๊ฐ ๋ ๊ฒ๋๋ค.