Running an app in Django. When Debug=True
it all works fine. When Debug=False
most of the app works fine except from a few static files, from what I was able to understand js files.
I run already python manage.py collectstatic
and the css
of the templates work, so the processs seems to have been succesful. Still though, a few JS files don't get loaded and this is messing up my admin panel.
This is the terminal error for the production environment (debug=False)
[21/Feb/2021 17:38:00] "GET /admin/ HTTP/1.1" 200 7803
[21/Feb/2021 17:38:00] "GET /static/admin/css/dashboard.css HTTP/1.1" 200 380
[21/Feb/2021 17:38:00] "GET /static/admin/img/icon-changelink.svg HTTP/1.1" 200 380
[21/Feb/2021 17:38:09] "GET /admin/amonthatatime/post/ HTTP/1.1" 200 9867
[21/Feb/2021 17:38:09] "GET /admin/jsi18n/ HTTP/1.1" 200 3187
[21/Feb/2021 17:38:11] "GET /admin/amonthatatime/post/1/change/ HTTP/1.1" 200 35171
[21/Feb/2021 17:38:11] "GET /admin/jsi18n/ HTTP/1.1" 200 3187
[21/Feb/2021 17:38:11] "GET /summernote/editor/id_medley/ HTTP/1.1" 200 7148
[21/Feb/2021 17:38:11] "GET /summernote/editor/id_whatsapp/ HTTP/1.1" 200 7154
[21/Feb/2021 17:38:11] "GET /static/summernote/lang/summernote-en-US.min.js?_=1613929091381 HTTP/1.1" 200 27
[21/Feb/2021 17:38:11] "GET /static/summernote/lang/summernote-en-US.min.js?_=1613929091408 HTTP/1.1" 200 27
This is my settings.py
from pathlib import Path
from django.conf import settings
from django.conf.urls.static import static
import os
import psycopg2
import dj_database_url
import cloudinary
# 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/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG_PROPAGATE_EXCEPTIONS = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'giaggi.herokuapp.com']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'amonthatatime.apps.AmonthatatimeConfig',
'django_summernote',
'cloudinary'
]
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 = 'giaggi.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'giaggi.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
MEDIA_URL = '/amonthatatime/static/amonthatatime/images/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'amonthatatime/static/amonthatatime/images/')
X_FRAME_OPTIONS = 'SAMEORIGIN'
#SECURE_SSL_REDIRECT=False
#SESSION_COOKIE_SECURE=False
#CSRF_COOKIE_SECURE=False
# Configure Django App for Heroku.
#import django_on_heroku
#django_on_heroku.settings(locals())