My Django project is opening very slowly on the server

Please check out my site: pyterminator.com The site opens very late. I don't know what the reason is. I used dj-static package in wsgi file. Does this affect performance?

wsgi.py :

import os
from dj_static import Cling 
from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')  
application = Cling(get_wsgi_application())

I bought the "Starter hosting" package and deployed there. Through C-Panel. Could this be the reason for poor performance?

I use these packages.

arabic-reshaper==3.0.0
asgiref==3.8.1
asn1crypto==1.5.1
certifi==2024.2.2
cffi==1.16.0
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
cryptography==42.0.6
cssselect2==0.7.0
dj-static==0.0.6
Django==5.0.4
django-cleanup==8.1.0
django-tinymce==4.0.0
html5lib==1.1
idna==3.7
lxml==5.2.1
mysqlclient==2.2.4
oscrypto==1.3.0
pillow==10.3.0
pycparser==2.22
pyHanko==0.24.0
pyhanko-certvalidator==0.26.3
pypdf==4.2.0
pypng==0.20220715.0
python-bidi==0.4.2
python-dotenv==1.0.1
PyYAML==6.0.1
qrcode==7.4.2
reportlab==4.0.9
requests==2.31.0
six==1.16.0
sqlparse==0.5.0
static3==0.7.0
svglib==1.5.1
tinycss2==1.3.0
typing_extensions==4.11.0
tzdata==2024.1
tzlocal==5.2
uritools==4.0.2
urllib3==2.2.1
webencodings==0.5.1
xhtml2pdf==0.2.15

settings.py

import os
from pathlib import Path

# ---------------------- * -------------------------
from django.contrib.messages import constants as messages 

# ---------------------- * -------------------------
from dotenv import load_dotenv 
load_dotenv() 

# ---------------------- * -------------------------
BASE_DIR = Path(__file__).resolve().parent.parent

# ---------------------- * -------------------------
SECRET_KEY = "xxxx"

# ---------------------- * -------------------------
DEBUG = True
ALLOWED_HOSTS = ["pyterminator.com", "127.0.0.1", "www.pyterminator.com"]

# ---------------------- * -------------------------
INSTALLED_APPS = [ 
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_cleanup.apps.CleanupConfig', 
    'tinymce',
    # ---> Apps <--- #
    'home.apps.HomeConfig',
    'post.apps.PostConfig',
    'fusion.apps.FusionConfig',
    'contact.apps.ContactConfig',
    'c_profile.apps.CProfileConfig',
]

# ---------------------- * -------------------------
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

# ---------------------- * -------------------------
ROOT_URLCONF = 'core.urls'

# ---------------------- * -------------------------
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
            # BASE_DIR.joinpath("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',
            ],
            'libraries':{
                'pylang': 'core.templatetags.pylang', 
            }
        },
    },
]

# ---------------------- * -------------------------
WSGI_APPLICATION = 'core.wsgi.application'

# ---------------------- * -------------------------


if DEBUG:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': BASE_DIR / 'db.sqlite3',
        },
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ.get("MYSQL_DB_NAME"),
            'USER': os.environ.get("MYSQL_DB_USER_NAME"),
            'PASSWORD': os.environ.get("MYSQL_DB_USER_PASSWORD"),
            'HOST': os.environ.get("SHARED_IP"),
            'PORT':'3306',
            'OPTIONS': {
                'sql_mode': 'STRICT_TRANS_TABLES',
                'charset': 'utf8mb4',
                'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
            }
        }, 
    }

# ---------------------- * -------------------------
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 = 'Asia/Baku'
USE_I18N = True
USE_TZ = True

# ---------------------- * -------------------------
STATIC_URL = 'static/'
STATICFILES_DIRS = [
    BASE_DIR / "static",
    os.path.join(BASE_DIR, "static")
]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

# ---------------------- * -------------------------
MEDIA_URL='/media/'
MEDIA_ROOT = BASE_DIR / 'media'

# ---------------------- * -------------------------
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# ---------------------- * -------------------------
X_FRAME_OPTIONS = 'DENY' # IFRAME qadagasi

# ---------------------- * -------------------------
TINYMCE_DEFAULT_CONFIG = {
    'plugins': ['code', 'template'],
}

# ---------------------- * -------------------------
MESSAGE_TAGS = {
    messages.INFO: 'alert-info',
    messages.SUCCESS: 'alert-success',
    messages.WARNING: 'alert-warning',
    messages.ERROR: 'alert-danger',
}

# ---------------------- * -------------------------
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
if DEBUG: 
    EMAIL_HOST = os.environ.get('LOCAL_EMAIL_HOST') 
    EMAIL_USE_TLS = True
    EMAIL_PORT = 587
    EMAIL_HOST_USER = os.environ.get("LOCAL_EMAIL_HOST_USER") 
    EMAIL_HOST_PASSWORD = os.environ.get("LOCAL_EMAIL_HOST_PASSWORD")
else:  
    EMAIL_HOST = os.environ.get('EMAIL_HOST') 
    EMAIL_USE_SSL = True  
    EMAIL_PORT = 465
    EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER") 
    EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
Back to Top