Skip to content

Commit

Permalink
feat: 프로젝트 초기세팅 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
pasitoapasito committed Jul 18, 2022
1 parent ca61c49 commit 048fb9e
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 27 deletions.
94 changes: 84 additions & 10 deletions ideaconcert/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os

from pathlib import Path
from dotenv import load_dotenv, find_dotenv

from django.core.exceptions import ImproperlyConfigured

load_dotenv(find_dotenv())

def get_env_variable(var_name):
try:
return os.environ[var_name]
except KeyError:
error_msg = f'Set the {var_name} environment variable'
raise ImproperlyConfigured(error_msg)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -20,30 +34,43 @@
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-_mq6zincrrt!36svw&1q79k5flvpi737=yx%frytkghp0xqbuo'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = get_env_variable('DEBUG')

ALLOWED_HOSTS = []
SECRET_KEY = get_env_variable('SECRET_KEY')
ALLOWED_HOSTS = (get_env_variable('ALLOWED_HOSTS'), )

APPEND_SLASH = False


# Application definition

PROJECT_APPS = [

]

THIRD_PARTY_APPS = [
'drf_yasg',
'corsheaders',
'rest_framework',
'django_extensions',
]

INSTALLED_APPS = [
'django.contrib.admin',
# 'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
'django.contrib.staticfiles',
] + THIRD_PARTY_APPS + PROJECT_APPS

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
Expand Down Expand Up @@ -99,27 +126,74 @@
},
]

##CORS
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True

CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
)

CORS_ALLOW_HEADERS = (
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
)

# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'ko-KR'

TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Seoul'

USE_I18N = True

USE_L10N = True

USE_TZ = True
USE_TZ = False


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

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser'
],
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
'UNAUTHENTICATED_USER': None,
}

SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
'Bearer': {
'type': 'apiKey',
'name': 'Authorization',
'in': 'header'
}
}
}
39 changes: 22 additions & 17 deletions ideaconcert/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
"""ideaconcert URL Configuration
from drf_yasg import openapi
from drf_yasg.views import get_schema_view

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from rest_framework import permissions
from django.urls import path, re_path, include


schema_view = get_schema_view(
openapi.Info(
title='ideaconcert API',
default_version='v1',
description='ideaconcert-project',
),
public=True,
permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
path('admin/', admin.site.urls),

]

urlpatterns += [
re_path(r'^swagger(?P<format>\.json|\.yaml)$',schema_view.without_ui(cache_timeout=0),name='schema-json',),
re_path(r'^swagger$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^redoc$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Django==4.0.6
djangorestframework==3.13.1
django-cors-headers==3.13.0
django-extensions==3.2.0
ipython==8.4.0
python-dotenv==0.20.0
drf-yasg==1.20.0

0 comments on commit 048fb9e

Please sign in to comment.