Use python-decouple for managing environment variables
This commit is contained in:
parent
58f7364688
commit
e0c122016a
@ -12,10 +12,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
import environ
|
from decouple import config
|
||||||
|
|
||||||
# Environment variables
|
|
||||||
env = environ.Env()
|
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
@ -120,11 +117,11 @@ ASGI_APPLICATION = "config.asgi.application"
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
||||||
"NAME": env("DB_NAME"),
|
"NAME": config("DB_NAME"),
|
||||||
"USER": env("DB_USER"),
|
"USER": config("DB_USER"),
|
||||||
"PASSWORD": env("DB_PASSWORD"),
|
"PASSWORD": config("DB_PASSWORD"),
|
||||||
"HOST": env("DB_HOST"),
|
"HOST": config("DB_HOST", default="localhost"),
|
||||||
"PORT": env("DB_PORT"),
|
"PORT": config("DB_PORT", default=5432),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +168,7 @@ STATIC_URL = "/static/"
|
|||||||
STATICFILES_DIRS = [
|
STATICFILES_DIRS = [
|
||||||
os.path.join(BASE_DIR, "static"),
|
os.path.join(BASE_DIR, "static"),
|
||||||
]
|
]
|
||||||
STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ["staticfiles"]))
|
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
|
||||||
|
|
||||||
MEDIA_URL = "/media/"
|
MEDIA_URL = "/media/"
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
||||||
@ -180,13 +177,11 @@ MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
|||||||
# E-mail configuration
|
# E-mail configuration
|
||||||
|
|
||||||
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
||||||
EMAIL_HOST = (
|
EMAIL_HOST = "smtp.gmail.com" # Gmail as the email host, but you can change it
|
||||||
"smtp.gmail.com" # Here i'm using gmail as the email host, but you can change it
|
EMAIL_PORT = config("EMAIL_PORT", default=587)
|
||||||
)
|
|
||||||
EMAIL_PORT = 587
|
|
||||||
EMAIL_USE_TLS = True
|
EMAIL_USE_TLS = True
|
||||||
EMAIL_HOST_USER = env("USER_EMAIL")
|
EMAIL_HOST_USER = config("USER_EMAIL")
|
||||||
EMAIL_HOST_PASSWORD = env("USER_PASSWORD")
|
EMAIL_HOST_PASSWORD = config("USER_PASSWORD")
|
||||||
|
|
||||||
# crispy config
|
# crispy config
|
||||||
CRISPY_TEMPLATE_PACK = "bootstrap4"
|
CRISPY_TEMPLATE_PACK = "bootstrap4"
|
||||||
@ -206,5 +201,5 @@ REST_FRAMEWORK = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Strip payment config
|
# Strip payment config
|
||||||
STRIPE_SECRET_KEY = env("STRIPE_SECRET_KEY")
|
STRIPE_SECRET_KEY = config("STRIPE_SECRET_KEY", default="")
|
||||||
STRIPE_PUBLISHABLE_KEY = env("STRIPE_PUBLISHABLE_KEY")
|
STRIPE_PUBLISHABLE_KEY = config("STRIPE_PUBLISHABLE_KEY", default="")
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
"""Django's command-line utility for administrative tasks."""
|
"""Django's command-line utility for administrative tasks."""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import environ
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -19,6 +18,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# OS environment variables take precedence over variables from .env
|
|
||||||
environ.Env.read_env()
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -10,7 +10,6 @@ hiredis==2.1.0 # https://github.com/redis/hiredis-py
|
|||||||
# Django
|
# Django
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
django==4.0.8 # pyup: < 4.1 # https://www.djangoproject.com/
|
django==4.0.8 # pyup: < 4.1 # https://www.djangoproject.com/
|
||||||
django-environ==0.9.0 # https://github.com/joke2k/django-environ
|
|
||||||
django-model-utils==4.3.1 # https://github.com/jazzband/django-model-utils
|
django-model-utils==4.3.1 # https://github.com/jazzband/django-model-utils
|
||||||
django-crispy-forms==1.14.0 # https://github.com/django-crispy-forms/django-crispy-forms
|
django-crispy-forms==1.14.0 # https://github.com/django-crispy-forms/django-crispy-forms
|
||||||
crispy-bootstrap5==0.7 # https://github.com/django-crispy-forms/crispy-bootstrap5
|
crispy-bootstrap5==0.7 # https://github.com/django-crispy-forms/crispy-bootstrap5
|
||||||
@ -28,3 +27,6 @@ gopay==2.0.1
|
|||||||
|
|
||||||
# Customize django admin
|
# Customize django admin
|
||||||
django-jet-reboot==1.3.5
|
django-jet-reboot==1.3.5
|
||||||
|
|
||||||
|
# Environment variable
|
||||||
|
python-decouple==3.8
|
||||||
Loading…
x
Reference in New Issue
Block a user