R
Railway13mo ago
Drekkenz

Django production Server Error or Interval Server Error with no logs

Project id: 1ba89116-6373-47f4-9cf9-785a08acae4c When deploying my site with DEBUG=True it works fine, but setting it to False even after setting allowed hosts to my custom domain just gives one of the two above errors. I cannot see the server logs in production and there are no deploy logs. I have whitenoise installed and fixed an issue where the collected static folder wasn't pushed as it was in the gitignore. My static tags seems to be fine and have no prepended slash and I can't see what else it could be. I even tried removing the static imports and it still wouldn't work. I have env variable of DISABLE_COLLECTSTATIC = 0 Relevant settings are below
ALLOWED_HOSTS = ['www.<my-site>.com', '<my-site>.com']
CSRF_TRUSTED_ORIGINS = ['https://<my-site>.com', 'http://<my-site>.com']
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'whitenoise.runserver_nostatic',
'crispy_forms',
'crispy_bootstrap4',
'main.apps.MainConfig',
'middleware',
'django_countries',
]
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',
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static_collected_files')
STATIC_URL = '/static/'
STATICFILES_STORAGE="whitenoise.storage.CompressedManifestStaticFilesStorage"

# Define the STATICFILES_DIRS to specify the directories where your static files are located.
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
DEBUG_PROPAGATE_EXCEPTIONS = True
ALLOWED_HOSTS = ['www.<my-site>.com', '<my-site>.com']
CSRF_TRUSTED_ORIGINS = ['https://<my-site>.com', 'http://<my-site>.com']
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'whitenoise.runserver_nostatic',
'crispy_forms',
'crispy_bootstrap4',
'main.apps.MainConfig',
'middleware',
'django_countries',
]
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',
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static_collected_files')
STATIC_URL = '/static/'
STATICFILES_STORAGE="whitenoise.storage.CompressedManifestStaticFilesStorage"

# Define the STATICFILES_DIRS to specify the directories where your static files are located.
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
DEBUG_PROPAGATE_EXCEPTIONS = True
Solution:
Adding python manage.py collectstatic --noinput to my ProcFile and fixing some filename references seemed to work
Jump to solution
9 Replies
Percy
Percy13mo ago
Project ID: 1ba89116-6373-47f4-9cf9-785a08acae4c
Drekkenz
Drekkenz13mo ago
Additionally I tried adding verbose logging for when DEBUG=False as below but don't know how to access them:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'mysite.log',
'formatter': 'verbose'
},
},
'loggers': {
'django': {
'handlers':['file'],
'propagate': True,
'level':'DEBUG',
},
'MYAPP': {
'handlers': ['file'],
'level': 'DEBUG',
},
}
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'mysite.log',
'formatter': 'verbose'
},
},
'loggers': {
'django': {
'handlers':['file'],
'propagate': True,
'level':'DEBUG',
},
'MYAPP': {
'handlers': ['file'],
'level': 'DEBUG',
},
}
}
My ProcFile: web: gunicorn <app>.wsgi --log-file gunicorn.log I can't tell that it's collecting static files either, should I add this to the procfile?
Brody
Brody13mo ago
you need to log to stdout / stderr or else you wont be able to see the logs in the deployment logs window, change your procfile to
web: gunicorn <app>.wsgi --log-file -
web: gunicorn <app>.wsgi --log-file -
as per their docs: https://docs.gunicorn.org/en/stable/settings.html#errorlog
Drekkenz
Drekkenz13mo ago
This is all that's logged now:
[2023-10-31 18:54:08 +0000] [1] [INFO] Starting gunicorn 21.2.0
[2023-10-31 18:54:08 +0000] [1] [INFO] Listening at: http://0.0.0.0:5681 (1)
[2023-10-31 18:54:08 +0000] [1] [INFO] Using worker: sync
[2023-10-31 18:54:08 +0000] [10] [INFO] Booting worker with pid: 10
[2023-10-31 18:54:08 +0000] [1] [INFO] Starting gunicorn 21.2.0
[2023-10-31 18:54:08 +0000] [1] [INFO] Listening at: http://0.0.0.0:5681 (1)
[2023-10-31 18:54:08 +0000] [1] [INFO] Using worker: sync
[2023-10-31 18:54:08 +0000] [10] [INFO] Booting worker with pid: 10
oh wait just got a bunch Okay seems something to do with static files ValueError: Missing staticfiles manifest entry for 'main/css/base.css'
Brody
Brody13mo ago
just a configuration error
Solution
Drekkenz
Drekkenz13mo ago
Adding python manage.py collectstatic --noinput to my ProcFile and fixing some filename references seemed to work
Brody
Brody13mo ago
perfect
Drekkenz
Drekkenz13mo ago
Thanks!
Brody
Brody13mo ago
no problem!
Want results from more Discord servers?
Add your server