본문 바로가기
수업(국비지원)/Django

[Django] 게시판 생성

by byeolsub 2023. 4. 27.

📌 settingd.py 내용 추가

"""
Django settings for study1 project.

Generated by 'django-admin startproject' using Django 4.1.4.

For more information on this file, see
<https://docs.djangoproject.com/en/4.1/topics/settings/>

For the full list of settings and their values, see
<https://docs.djangoproject.com/en/4.1/ref/settings/>
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See <https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/>

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-zskt0=@(+^8=+-&_+_!!3fbt=_hyw&+0!@-epor%4!vo&72@tv"

# 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",
    "member",
    **"board",**
]

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 = "study1.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR/'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 = "study1.wsgi.application"

# Database
# <https://docs.djangoproject.com/en/4.1/ref/settings/#databases>
'''
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3", 
    }
}
'''

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": 'kic',
        "USER": 'kic',
        "PASSWORD": '1234',
        "HOST": 'localhost',
        "PORT": '3307'
    }
}

# Password validation
# <https://docs.djangoproject.com/en/4.1/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/4.1/topics/i18n/>

# LANGUAGE_CODE = "en-us"
LANGUAGE_CODE = "ko-kr"

# TIME_ZONE = "UTC"
TIME_ZONE = "Asia/Seoul"

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# <https://docs.djangoproject.com/en/4.1/howto/static-files/>

STATIC_URL = "/static/" # css, js 파일의 위치

# Default primary key field type
# <https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field>

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

import os
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]  # css, js 파일의 위치 폴더 설정

# 파일 업로드 폴더, URL설정 
MEDIA_URL = "/file/"
MEDIA_ROOT = os.path.join(BASE_DIR,"file")

📌 board/models.py 내용 생성

**from django.db import models

# Create your models here.
# python manage.py makemigrations
# python manage.py migrate

class Board(models.Model) :
    num = models.AutoField(primary_key=True)
    name = models.CharField(max_length=30)
    pass1 = models.CharField(max_length=20)
    subject = models.CharField(max_length=100)
    content = models.CharField(max_length=4000)
    regdate = models.DateTimeField()
    readcnt = models.IntegerField(default=0)
    file1 = models.CharField(max_length=300)
    
def __str__(self) :
   return str(self.num) + ":" + self.subject**

 

'수업(국비지원) > Django' 카테고리의 다른 글

[Django] 게시판 목록  (0) 2023.04.27
[Django] 게시판 등록  (0) 2023.04.27
[Django] 비밀번호 수정  (0) 2023.04.27
[Django] 파일 업로드  (0) 2023.04.27
[Django] 회원탈퇴  (0) 2023.04.27