chore: integrate django-environ, create .env-example, and move sensitive settings to .env
This commit is contained in:
parent
3b2f8aee30
commit
66bbb57548
7 changed files with 49 additions and 45 deletions
2
backend/.gitignore
vendored
2
backend/.gitignore
vendored
|
|
@ -147,4 +147,4 @@ GitHub.sublime-settings
|
|||
videoflix/users/migrations
|
||||
|
||||
# Statics
|
||||
videoflix/staticfiles
|
||||
staticfiles
|
||||
|
|
@ -5,6 +5,7 @@ click==8.1.7
|
|||
diff-match-patch==20230430
|
||||
Django==5.0.8
|
||||
django-cors-headers==4.4.0
|
||||
django-environ==0.12.0
|
||||
django-grip==3.5.0
|
||||
django-import-export==4.1.1
|
||||
django-redis==5.4.0
|
||||
|
|
@ -23,7 +24,6 @@ psutil==6.0.0
|
|||
psycopg==3.2.6
|
||||
pubcontrol==3.5.0
|
||||
PyJWT==2.9.0
|
||||
python-decouple==3.8
|
||||
redis==5.0.8
|
||||
requests==2.32.3
|
||||
rq==1.16.2
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
}
|
||||
</style>
|
||||
<body>
|
||||
<div class="center"><img src="https://andre-kempf.com/videoflix-logo.png" alt=""></div>
|
||||
<div class="center"><img src="https://videoflix.andre-kempf.com/assets/img/videoflix-logo.png" alt="Videoflix"></div>
|
||||
<p>Dear {{ name }},</p>
|
||||
<p>
|
||||
We recently received a request to reset your password. If you made this request, please click on the following link to reset your password:
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
}
|
||||
</style>
|
||||
<body>
|
||||
<div class="center"><img src="https://andre-kempf.com/videoflix-logo.png" alt=""></div>
|
||||
<div class="center"><img src="https://videoflix.andre-kempf.com/assets/img/videoflix-logo.png" alt="Videoflix"></div>
|
||||
<p>Dear {{ name }},</p>
|
||||
<p>
|
||||
Thank you for registering with Videoflix. To complete your registration
|
||||
|
|
|
|||
13
backend/videoflix/.env_example
Normal file
13
backend/videoflix/.env_example
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# General settings
|
||||
|
||||
DEBUG=False
|
||||
SECRET_KEY=secret_key
|
||||
|
||||
# E-mail settings
|
||||
|
||||
EMAIL_HOST_USER=example@gmail.com
|
||||
EMAIL_HOST_PASSWORD=password
|
||||
|
||||
# Sentry settings
|
||||
|
||||
SENTRY_DSN=sentry_dns
|
||||
|
|
@ -11,32 +11,14 @@ https://docs.djangoproject.com/en/5.0/ref/settings/
|
|||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from decouple import config
|
||||
import sentry_sdk
|
||||
from pathlib import Path
|
||||
from environ import Env
|
||||
from sentry_sdk.integrations.django import DjangoIntegration
|
||||
|
||||
# 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/5.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-*o%q)*3l+9^fs!m0z_h=z9bc)su=%)fv$@ktb#pza-pvi^z*en'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
# EMAIL
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST = 'smtp.gmail.com'
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
|
||||
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
DEFAULT_FROM_EMAIL = 'noreply@videoflix.com'
|
||||
|
||||
ALLOWED_HOSTS = [
|
||||
'videoflix-api.andre-kempf.com',
|
||||
'45.157.177.172',
|
||||
|
|
@ -189,7 +171,7 @@ USE_TZ = True
|
|||
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
IMPORT_EXPORT_USE_TRANSACTIONS = True
|
||||
|
||||
|
|
@ -217,10 +199,29 @@ AUTHENTICATION_BACKENDS = (
|
|||
'django.contrib.auth.backends.ModelBackend',
|
||||
)
|
||||
|
||||
# Environment variables
|
||||
|
||||
env = Env()
|
||||
Env.read_env()
|
||||
|
||||
DEBUG = env.bool('DEBUG', default=False)
|
||||
SECRET_KEY = env('SECRET_KEY')
|
||||
|
||||
# Mail
|
||||
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST = 'smtp.gmail.com'
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_HOST_USER = env('EMAIL_HOST_USER', default='')
|
||||
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD', default='')
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
DEFAULT_FROM_EMAIL = 'noreply@videoflix.andre-kempf.com'
|
||||
|
||||
# Sentry
|
||||
|
||||
sentry_sdk.init(
|
||||
dsn="https://f9cac097dbb7a0d104f07d347e1bd470@o4507955559464960.ingest.de.sentry.io/4507955586138192",
|
||||
dsn=os.getenv("SENTRY_DSN"),
|
||||
integrations=[DjangoIntegration()],
|
||||
traces_sample_rate=1.0,
|
||||
profiles_sample_rate=1.0,
|
||||
)
|
||||
|
|
@ -1,23 +1,8 @@
|
|||
"""
|
||||
URL configuration for videoflix project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/5.0/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, include
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from user_app import views as user_views
|
||||
from auth_app.views import (
|
||||
LoginView,
|
||||
|
|
@ -29,7 +14,6 @@ from auth_app.views import (
|
|||
ChangePasswordView
|
||||
)
|
||||
from video_app import views as video_views
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
|
@ -54,4 +38,10 @@ urlpatterns = [
|
|||
path('auth/verify-email/', VerifyEmailView.as_view(), name='verify_email'),
|
||||
path('auth/forgot-password/', ForgotPasswordView.as_view(), name='forgot_password'),
|
||||
path('auth/change-password/', ChangePasswordView.as_view(), name='change_password'),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + staticfiles_urlpatterns()
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
Loading…
Reference in a new issue