Answer the question
In order to leave comments, you need to log in
How to set Debug=False correctly?
Good afternoon!
Can't get site up on Heroku in Debug=False
.
When Debug=True
- everything works fine. But as soon as I change and make git push heroku master
the site gives out 500 code.
With all this, judging by the logs, he is persistently looking for favicon.ico. Although I even removed it from the page code, the site still does not stop trying to find it. Now like this:
<link rel="shortcut icon" type='image/x-icon' href="{% static 'favicon.ico' %}">
<link rel="icon" type='image/x-icon' href="{% static 'favicon.ico' %}">
ValueError: Missing staticfiles manifest entry for 'favicon.ico'
app[web.1]: "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"
app[web.1]: "GET /favicon.ico HTTP/1.1" 302 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"
heroku[router]: at=info method=GET path="/" host=***.herokuapp.com request_id=eeb0d4ac94ab-a77ca154 fwd="***.***.***.***" dyno=web.1 connect=1ms service=5ms status=500 bytes=366 protocol=https
heroku[router]: at=info method=GET path="/favicon.ico" host=***.herokuapp.com request_id=8eb68f44--2ea5e173f93f fwd="***.***.***.***" dyno=web.1 connect=1ms service=2ms status=302 bytes=256 protocol=https
"""
Django settings for dj project.
Generated by 'django-admin startproject' using Django 3.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
import django_heroku
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
#SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'rest_framework',
]
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 = 'dj.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 = 'dj.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/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.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
#PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Activate Django-Heroku.
django_heroku.settings(locals())
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
},
},
}
app_name = "blog"
urlpatterns = [
path('', views.post_list, name='post_list'),
url(r'^api/article/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
path('article/', views.article, name='article'),
url(r'^favicon\.ico$',RedirectView.as_view(url='/static/images/favicon.ico')),
]
app_name = "blog"
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
]
Answer the question
In order to leave comments, you need to log in
When you turn off DEBUG, Django changes 2 main things:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question