mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 07:52:54 +00:00
✨ Features: - Complete Django project with authentication - Email/password and social login (Google, Facebook) - Role-based access control (admin, staff, user) - Docker and Docker Compose setup - Production-ready configuration - Static file handling with WhiteNoise - PostgreSQL database integration - Comprehensive documentation - GitHub CI/CD workflows - Dokploy deployment configuration 🚀 Ready for deployment on Dokploy, Heroku, Railway, and other platforms
180 lines
5.1 KiB
Python
180 lines
5.1 KiB
Python
"""
|
|
Base settings for Django project.
|
|
"""
|
|
import os
|
|
from pathlib import Path
|
|
from decouple import config
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
|
SECRET_KEY = config('SECRET_KEY', default='django-insecure-change-this-in-production')
|
|
|
|
DEBUG = config('DEBUG', default=False, cast=bool)
|
|
|
|
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost,127.0.0.1', cast=lambda v: [s.strip() for s in v.split(',')])
|
|
|
|
DJANGO_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'django.contrib.sites',
|
|
]
|
|
|
|
THIRD_PARTY_APPS = [
|
|
'allauth',
|
|
'allauth.account',
|
|
'allauth.socialaccount',
|
|
'allauth.socialaccount.providers.google',
|
|
'allauth.socialaccount.providers.facebook',
|
|
'whitenoise.runserver_nostatic',
|
|
]
|
|
|
|
LOCAL_APPS = [
|
|
'apps.accounts',
|
|
'apps.core',
|
|
]
|
|
|
|
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
|
|
|
MIDDLEWARE = [
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'whitenoise.middleware.WhiteNoiseMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'allauth.account.middleware.AccountMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'django_project.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [BASE_DIR / 'templates'],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.debug',
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'django_project.wsgi.application'
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.postgresql',
|
|
'NAME': config('DB_NAME', default='django_db'),
|
|
'USER': config('DB_USER', default='django_user'),
|
|
'PASSWORD': config('DB_PASSWORD', default='django_password'),
|
|
'HOST': config('DB_HOST', default='localhost'),
|
|
'PORT': config('DB_PORT', default='5432'),
|
|
}
|
|
}
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
},
|
|
]
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
TIME_ZONE = 'UTC'
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
STATICFILES_DIRS = [BASE_DIR / 'static']
|
|
|
|
MEDIA_URL = '/media/'
|
|
MEDIA_ROOT = BASE_DIR / 'media'
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
AUTH_USER_MODEL = 'accounts.User'
|
|
|
|
SITE_ID = 1
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
'django.contrib.auth.backends.ModelBackend',
|
|
'allauth.account.auth_backends.AuthenticationBackend',
|
|
]
|
|
|
|
ACCOUNT_AUTHENTICATION_METHOD = 'email'
|
|
ACCOUNT_EMAIL_REQUIRED = True
|
|
ACCOUNT_USERNAME_REQUIRED = False
|
|
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
|
|
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
|
|
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
|
|
ACCOUNT_LOGOUT_ON_GET = True
|
|
ACCOUNT_SESSION_REMEMBER = True
|
|
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = True
|
|
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
|
|
ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 300
|
|
|
|
LOGIN_URL = '/accounts/login/'
|
|
LOGIN_REDIRECT_URL = '/'
|
|
LOGOUT_REDIRECT_URL = '/'
|
|
|
|
EMAIL_BACKEND = config('EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend')
|
|
EMAIL_HOST = config('EMAIL_HOST', default='localhost')
|
|
EMAIL_PORT = config('EMAIL_PORT', default=587, cast=int)
|
|
EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=True, cast=bool)
|
|
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
|
|
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
|
|
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL', default='noreply@example.com')
|
|
|
|
SOCIALACCOUNT_PROVIDERS = {
|
|
'google': {
|
|
'SCOPE': [
|
|
'profile',
|
|
'email',
|
|
],
|
|
'AUTH_PARAMS': {
|
|
'access_type': 'online',
|
|
},
|
|
'OAUTH_PKCE_ENABLED': True,
|
|
},
|
|
'facebook': {
|
|
'METHOD': 'oauth2',
|
|
'SCOPE': ['email', 'public_profile'],
|
|
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
|
|
'INIT_PARAMS': {'cookie': True},
|
|
'FIELDS': [
|
|
'id',
|
|
'first_name',
|
|
'last_name',
|
|
'middle_name',
|
|
'name',
|
|
'name_format',
|
|
'picture',
|
|
'short_name'
|
|
],
|
|
'EXCHANGE_TOKEN': True,
|
|
'LOCALE_FUNC': 'path.to.callable',
|
|
'VERIFIED_EMAIL': False,
|
|
'VERSION': 'v7.0',
|
|
}
|
|
}
|
|
|
|
SOCIALACCOUNT_LOGIN_ON_GET = True |