initially make meterplus.ir ready for production

This commit is contained in:
Hadi 2025-10-08 14:04:58 +03:30
parent 672e26c89d
commit bb1b1a8ebf
3 changed files with 55 additions and 23 deletions

View file

@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
"""
import os
from pathlib import Path
from decouple import config
import dj_database_url
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@ -20,16 +22,28 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-h!2hx$h=f6ktgdks!g2_*pg_s1nnuyk+j2yd*_x8r+3+3iyfy*'
SECRET_KEY = config('DJANGO_SECRET_KEY', default="unsecure-secretkey-kjhsgfjsfgjsfgjsg")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = config('DEBUG', cast=bool, default=True)
ALLOWED_HOSTS = []
# Allowed hosts
ALLOWED_HOSTS = [host for host in config("DJANGO_ALLOWED_HOSTS", default="").split() if host]
# URL scheme (http or https)
URL_SCHEME = config("URL_SCHEME", default="http")
# CSRF trusted origins (add both with and without port if you use a non-standard port)
CSRF_TRUSTED_ORIGINS = []
for host in ALLOWED_HOSTS:
if host not in ("localhost", "127.0.0.1"):
CSRF_TRUSTED_ORIGINS.append(f"{URL_SCHEME}://{host}")
# Generate base URL for absolute URLs (use first allowed host)
BASE_URL = f"{URL_SCHEME}://{ALLOWED_HOSTS[0]}" if ALLOWED_HOSTS else "http://localhost"
# Application definition
INSTALLED_APPS = [
# ------ theme ------ #
'jazzmin',
@ -45,6 +59,7 @@ INSTALLED_APPS = [
# ------- third party apps ------- #
'simple_history',
'django_extensions',
# -------------------------------- #
# ------- my apps ------- #
@ -96,13 +111,20 @@ WSGI_APPLICATION = '_base.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
DB_TYPE = config('DB_TYPE', default='sqlite').lower()
if DB_TYPE == 'postgres':
DATABASES = {
'default': dj_database_url.config(default=config('DATABASE_URL'))
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR/"db.sqlite3",
}
}
# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
@ -139,15 +161,15 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_ROOT = 'ss'
STATIC_URL = 'static/'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
os.path.join(BASE_DIR, 'static'),
]
# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field