이 κ°€μ΄λ“œλŠ” 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
# 이미 μ‚¬μš© 쀑인 포트 확인 κ°€λŠ₯

πŸ›‘οΈ λ³΄μ•ˆ κ΄€λ ¨ μ£Όμ˜μ‚¬ν•­

  1. **SECRET_KEY**λŠ” μ ˆλŒ€ κ³΅κ°œν•˜μ§€ λ§ˆμ„Έμš”! πŸ”’
  2. **DEBUG = True**λŠ” 개발 ν™˜κ²½μ—μ„œλ§Œ μ‚¬μš©ν•˜μ„Έμš”. ⚠️

1️⃣2️⃣ λ‹€μŒ 단계

  • πŸ”‘ κ΄€λ¦¬μž 계정 생성: python manage.py createsuperuser
  • πŸ› οΈ μ•± 개발 μ‹œμž‘
  • πŸš€ ν”„λ‘œλ•μ…˜ 배포 μ€€λΉ„

πŸŽ‰ 이제 Django 개발 μ„œλ²„κ°€ μ„±κ³΅μ μœΌλ‘œ μ„€μΉ˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€! πŸ™Œ
μΆ”κ°€ 질문이 μžˆλ‹€λ©΄ μ–Έμ œλ“ μ§€ λ¬Έμ˜ν•΄μ£Όμ„Έμš”. 😊