์ƒˆ์†Œ์‹

๐Ÿ ํŒŒ์ด์ฌ (Python)

์žฅ๊ณ  (Django) - ์„ค์น˜ , ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ, ์•ฑ ๋งŒ๋“ค๊ธฐ , ์•ฑ ๋“ฑ๋กํ•˜๊ธฐ

  • -

*์žฅ๊ณ  ์„ค์น˜ํ•˜๊ธฐ

* 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 ์ด๋ฆ„์„ ์ ์œผ๋ฉด ์‚ฌ์šฉํ•  ์ค€๋น„๊ฐ€ ๋œ ๊ฒ๋‹ˆ๋‹ค.

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.