Skip to content

Instantly share code, notes, and snippets.

@dcortesnet
Created November 27, 2022 12:33
Show Gist options
  • Select an option

  • Save dcortesnet/4b35caf0d0f6cd6e346dcc81457c78bb to your computer and use it in GitHub Desktop.

Select an option

Save dcortesnet/4b35caf0d0f6cd6e346dcc81457c78bb to your computer and use it in GitHub Desktop.
Django example config started
"""
Django settings for school_service project.
Generated by 'django-admin startproject' using Django 3.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
import sys
import os
from dotenv import load_dotenv
import dj_database_url
from django.core.management.commands.runserver import Command as runserver
DEFAULT_PORT = 9097
load_dotenv()
runserver.default_port = DEFAULT_PORT
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["*"]
CORS_ORIGIN_ALLOW_ALL = True
INSTALLED_APPS = [
"django.contrib.contenttypes",
"django.contrib.staticfiles",
"corsheaders",
"rest_framework",
"drf_yasg",
"api",
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
]
ROOT_URLCONF = "school_service.urls"
MIGRATION_MODULES = {"school_service": False}
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {},
},
]
WSGI_APPLICATION = "school_service.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
if sys.argv[1] == "test":
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
else:
DATABASES = {
"default": {},
"brazil": dj_database_url.config(default=os.getenv("DATABASE_BRAZIL_URL")),
"peru": dj_database_url.config(default=os.getenv("DATABASE_PERU_URL")),
"ecuador": dj_database_url.config(default=os.getenv("DATABASE_ECUADOR_URL")),
}
# Internationalization
# https://docs.djangoproject.com/en/3.1/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.1/howto/static-files/
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# Rest framework settings
REST_FRAMEWORK = {
"UNAUTHENTICATED_USER": None,
"DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",),
}
# Swagger settings
SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
}
},
"USE_SESSION_AUTH": False,
"VALIDATOR_URL": "http://localhost:9090",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment