Moved my project to my production server on namescheap. Noticing however that while the pages are loading the static files (css,js and images) do not seem to be loading.
I have tried to read the django documentation to understand if there are any settings that I need to change when moving from development to production and tried to read similar questions on stackoverflow but still have the same issue.
This is what I have in my settings
...
DEBUG = False
# DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False'
ALLOWED_HOSTS = ["thegradientboost.com", "localhost", "127.0.0.1","http://thegradientboost.com/gradientboost"]
# Application definition
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
# 'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'django.contrib.humanize',
'crispy_forms',
'classroom',
]
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',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'django_school.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(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_school.wsgi.application'
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'allstaticfiles')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'public/static'),
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'
#deployment
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 60
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_HSTS_PRELOAD = True
SECURE_REFERRER_POLICY = "same-origin"
wsgi:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_school.settings")
application = get_wsgi_application()
the structure of the files in my project
gradboost
-->__pycache__
-->allstaticfiles
admin
css
second
third
fourth
-->classroom
__init__.py
apps.py
decorators.py
forms.py
models.py
urls.py
------>templates
------>templatetags
-->django_school
__pycache__
__init__.py
settings.py
urls.py
wsgi.py
-->public
-->static
css
second
third
fourth
-->templates
-->tmp
manage.py
passenger_wsgi.py
public_html
and how I load static in my html pages
...
{ % load static %}
...
<link rel="stylesheet" href="{% static 'third/css/bootstrap.css' %}">