diff --git a/blog/blog/settings.py b/blog/blog/settings.py index 65f4c6c..5e5eaec 100644 --- a/blog/blog/settings.py +++ b/blog/blog/settings.py @@ -12,22 +12,34 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ from pathlib import Path import os +import environ -# Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent + +environ.Env.read_env(os.path.join(BASE_DIR, ".env")) +env = environ.Env( + # set casting, default value + DEBUG=(bool, False), + DEVELOPMENT_MODE=(bool, False), +) + +# Build paths inside the project like this: BASE_DIR / 'subdir'. + PROJECT_ROOT = os.path.dirname(__file__) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-+-=x#$t4ympabt6#3#k=5t2w60%uiz7l6une62r+i6@sw9jds(" +SECRET_KEY = env("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - +DEBUG = env("DEBUG") +DEVELOPMENT_MODE = env("DEVELOPMENT_MODE") +ALLOWED_HOSTS = ["127.0.0.1"] +CSRF_TRUSTED_ORIGINS = [ + "http://127.0.0.1:50505", +] # Application definition @@ -76,14 +88,22 @@ WSGI_APPLICATION = "blog.wsgi.application" # Database # https://docs.djangoproject.com/en/4.0/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", +if DEVELOPMENT_MODE: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + } + } +else: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "OPTIONS": { + "service": "django_test", + }, + } } -} - # Password validation # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators @@ -121,13 +141,12 @@ USE_TZ = True STATIC_URL = "static/" -# пути для загрузки файлов -MEDIA_ROOT = os.path.join(BASE_DIR, "data/") # 'data' is my media folder -MEDIA_URL = "/media/" +if not DEVELOPMENT_MODE: + STATIC_ROOT = env("STATIC_ROOT") # для того чтобы использовать общие статические файлы STATICFILES_DIRS = [ - BASE_DIR / "static", + os.path.join(BASE_DIR, "static"), ] # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field diff --git a/req.txt b/req.txt new file mode 100644 index 0000000..21c4beb --- /dev/null +++ b/req.txt @@ -0,0 +1,7 @@ +asgiref==3.5.0 +Django==4.0.3 +django-environ==0.8.1 +gunicorn==20.1.0 +Pillow==9.1.0 +psycopg2-binary==2.9.3 +sqlparse==0.4.2