μ΄ κ°μ΄λλ Shop2World μΉνΈμ€ν κ³μ μμ μλΈλλ©μΈμ Django κ°λ° μλ²λ₯Ό μ€μΉνλ λ°©λ²μ μλ΄ν©λλ€. π
- μμμκ°: μ½ 5λΆ β±οΈ
- νμ 쑰건: μλΈλλ©μΈ μμ± μλ£ β
- λμ: Shop2World μΉμλΉμ€ μ¬μ©μ π₯
1οΈβ£ Python 3.6 μ€μΉ νμΈ π
python3.6 -V # Python 3.6.15
2οΈβ£ νλ‘μ νΈ λλ ν 리 μμ± λ° μ΄λ π(λλ μμ±ν μλΈλλ©μΈ λλ ν 리 μ΄λ)
cd /var/www/vhosts/shop2world.info/python.shop2world.info
3οΈβ£ κ°μνκ²½ μμ± λ° νμ±ν π
python3.6 -m virtualenv venv
source venv/bin/activate
π‘ κ°μνκ²½ νμ±ν νμΈ λ°©λ²:
(venv)
νμκ° ν둬ννΈ μμ λνλμΌ ν©λλ€.python --version
μΌλ‘ λ²μ μ¬νμΈ π§
4οΈβ£ Django λ° pysqlite3 μ€μΉ π
pip install Django==2.2.28
pip install pysqlite3-binary
5οΈβ£ Django νλ‘μ νΈ μμ± ποΈ
django-admin startproject config .
6οΈβ£ settings.py
μμ π οΈ (configν΄λμ μμ)
import sys
import pysqlite3
sys.modules['sqlite3'] = pysqlite3
import os
os.environ.setdefault('PYTHONIOENCODING', 'utf-8')
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'μ¬λ¬λΆμ μν¬λ¦Ώ ν€'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['python.shop2world.info', 'www.python.shop2world.info', 'localhost', '127.0.0.1', '*'] #μμ μ λλ©μΈμΌλ‘ λ³κ²½
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'config.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 = 'config.wsgi.application'
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': str(BASE_DIR / 'db.sqlite3'),
}
}
# Password validation
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
LANGUAGE_CODE = 'en-us' # 'ko-kr'μμ 'en-us'λ‘ λ³κ²½
TIME_ZONE = 'Asia/Seoul'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = str(BASE_DIR / 'static')
# STATICFILES_DIRS μΆκ°
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles'),
]
# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = str(BASE_DIR / 'media')
# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Security Settings (κ°λ° λͺ¨λμμλ λΉνμ±ν)
# SECURE_SSL_REDIRECT = True
# SESSION_COOKIE_SECURE = True
# CSRF_COOKIE_SECURE = True
7οΈβ£ νμν λλ ν 리 μμ± π
mkdir static media staticfiles
8οΈβ£ μ μ νμΌ μμ§ λ° λ°μ΄ν°λ² μ΄μ€ λ§μ΄κ·Έλ μ΄μ π¦
python manage.py collectstatic
python manage.py migrate
9οΈβ£ κ°λ° μλ² μ€ν π§
python manage.py runserver 0.0.0.0:8000
π λΈλΌμ°μ μμ **http://μλλ©μΈ:8000
**μΌλ‘ μ μν΄ νμΈνμΈμ. β
π ν¬νΈλ²νΈ μ£Όμμ¬ν
μ΄λ―Έ λ€λ₯Έ μλΈλλ©μΈμμ μ€ν μ€μ΄λΌλ©΄ ν¬νΈλ₯Ό λ€λ₯΄κ² μ§μ νμΈμ:
python manage.py runserver 0.0.0.0:8001
π‘ ν¬νΈ μ¬μ© νμΈ:
ps aux | grep runserver
# μ΄λ―Έ μ¬μ© μ€μΈ ν¬νΈ νμΈ κ°λ₯
π‘οΈ λ³΄μ κ΄λ ¨ μ£Όμμ¬ν
- **
SECRET_KEY
**λ μ λ 곡κ°νμ§ λ§μΈμ! π - **
DEBUG = True
**λ κ°λ° νκ²½μμλ§ μ¬μ©νμΈμ. β οΈ
1οΈβ£2οΈβ£ λ€μ λ¨κ³
- π κ΄λ¦¬μ κ³μ μμ±:
python manage.py createsuperuser
- π οΈ μ± κ°λ° μμ
- π νλ‘λμ λ°°ν¬ μ€λΉ
π μ΄μ Django κ°λ° μλ²κ° μ±κ³΅μ μΌλ‘ μ€μΉλμμ΅λλ€! π
μΆκ° μ§λ¬Έμ΄ μλ€λ©΄ μΈμ λ μ§ λ¬Έμν΄μ£ΌμΈμ. π
μ΅κ·Όλν