# Deploy Django with DEBUG = False

**URL:** <https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489>\
**Category:** Using Django\
**Created:** [August 31, 2021, 1:30pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489 "2021-08-31T13:30:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smailt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smailt/32/8270_2.png) [@smailt](https://forum.djangoproject.com/u/smailt)\
**Post date:** [August 31, 2021, 1:30pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489/1 "2021-08-31T13:30:43Z")

</div>

Hello  
My application works pretty well with DEBUG = True.

and when I change the DEBUG to False only pages and data from SQLite works.

no files, images, and styles works.  
for example the excel file:

 ![tddd](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/1/1940e06bd6c409ac7b64929fe7203df6b241336d.jpeg)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 31, 2021, 1:33pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489/2 "2021-08-31T13:33:21Z")

</div>

Is this the same issue as what you’re describing here? ([Deploy Django with Apache and mod\_wsgi](https://forum.djangoproject.com/t/deploy-django-with-apache-and-mod-wsgi/9468/)) If so, there’s no need to open up new conversations for it. Further discussion can continue there.

---

<div class="post-metadata">

**Author:** ![smailt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smailt/32/8270_2.png) [@smailt](https://forum.djangoproject.com/u/smailt)\
**Post date:** [August 31, 2021, 2:21pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489/3 "2021-08-31T14:21:38Z")

</div>

> [@KenWhitesell](#):
>
> n continue the

it is not the same, the other were about Apache and it finished by this.  
I’d answered and found the solution of the Apache issue and this is another issue.  
All my best

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 31, 2021, 2:28pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489/4 "2021-08-31T14:28:23Z")

</div>

Ok, so then to address this, we’ll need to see your settings.py file for this application, along with whatever server configuration components being used. (Is this also Apache?)

Note: Having DEBUG=True changes _many_ things within Django regarding file handling - getting different results with changing DEBUG=True to DEBUG=False is expected.

It may help for you to review the docs on:

- [Deploying Django | Django documentation | Django](https://docs.djangoproject.com/en/3.2/howto/deployment/)
- [Deployment checklist | Django documentation | Django](https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/)
- [Managing static files (e.g. images, JavaScript, CSS) | Django documentation | Django](https://docs.djangoproject.com/en/3.2/howto/static-files/)
- [Managing files | Django documentation | Django](https://docs.djangoproject.com/en/3.2/topics/files/)
- [settings for MEDIA\_ROOT and MEDIA\_URL](https://docs.djangoproject.com/en/3.2/ref/settings/#media-root)

---

<div class="post-metadata">

**Author:** ![smailt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smailt/32/8270_2.png) [@smailt](https://forum.djangoproject.com/u/smailt)\
**Post date:** [August 31, 2021, 2:50pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489/5 "2021-08-31T14:50:52Z")

</div>

> [@KenWhitesell](#):
>
> Is this also Apach

it is not with Apache just I run it `python manage.py runserver`

and this is my settings.py:

```auto
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath( __file__ )))

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$si5l1gh!d1mh=ksix($j7lklc%)qdl21chyfye1$%g#)3n4sv'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False 

ALLOWED_HOSTS = ['localhost','127.0.0.1','10.3.6.38']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'Home',
    'user',
    'crispy_forms',
    'django_filters',
    'mathfilters',
    'ckeditor',
    'rest_framework',
    'import_export',
]

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 = 'WikiPed.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 = 'WikiPed.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

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 = 'UTC' 
USE_I18N = True
USE_L10N = True
USE_TZ = True

  
STATIC_URL = '/Home/static/' 
STATICFILES_DIRS =[
    os.path.join(BASE_DIR,'Home/static/'),]
TEMPLATE_DIRS = (os.path.join(BASE_DIR, '/Home/templates/'),)
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'Home/static')
print(BASE_DIR)

CRISPY_TEMPLATE_PACK='bootstrap4'  
LOGIN_REDIRECT_URL='EnentWorkOver'
LOGIN_URL ='login'
MEDIA_ROOT =os.path.join(BASE_DIR,'media/')
MEDIA_URL = '/media/'  

#SMTP Configuration
#EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'XXXXXXXXX@gmail.com'
EMAIL_HOST_PASSWORD = "XXXXXXXX"

EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH =os.path.join(BASE_DIR,"media/sent_mails/")

DEFAULT_FROM_EMAIL="WikiPED <XXXXXXXXX@gmail.com>"

```

and this is my urls.py

```auto
from django.contrib import admin
from django.urls import path , include
from Home import views
from django.conf.urls.static import static
from django.conf import setting
from user import views as Userviews2
from django.contrib.auth import views as auth_views
from django.conf.urls import url
import os

handler404 = 'tutorial.views.custom_404'
urlpatterns = [
    path('', views.Home, name='WikiPED'),
    path('admin/', admin.site.urls),
    path('About/', views.about ,name='AboutWiki'),
    path('register/', Userviews2.register ,name='register'),
    path('login/', Userviews2.login_user ,name='login'),
    path('logout/', Userviews2.logout_user ,name='logout'),
    path('forbidden/', Userviews2.permission ,name='Permission'),
    path('Notes/', Userviews2.AutoComplet ,name='Autofield'),
    path('Div_EP/', views.Div_EP ,name='Div_EP'),
    path('Scheduling/', views.Scheduling ,name='Scheduling'),
    path('Add_Contrat/', views.Contratadd.as_view(), name='Add_Contrat'),
    path('Up_Contrat/<slug:pk>/update/', views.ContratUpadtW.as_view(), name='Up_Contrat'),
    path('dlt_Contrat/<slug:pk>/delete/', views.Contratdlt.as_view(), name='dlt_Contrat'),
    path('Contrat_detail/<int:id_itm>/', views.Contrat_detail, name='Contrat_detail'),

] + static(settings.MEDIA_URL , document_root=settings.MEDIA_ROOT)
```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 31, 2021, 3:01pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489/6 "2021-08-31T15:01:17Z")

</div>

See the --insecure parameter of the [runserver](https://docs.djangoproject.com/en/3.2/ref/contrib/staticfiles/#runserver) command and [Serving files uploaded by a user during development](https://docs.djangoproject.com/en/3.2/howto/static-files/#serving-files-uploaded-by-a-user-during-development) - particularly the green note at the bottom of that section.

---

<div class="post-metadata">

**Author:** ![smailt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smailt/32/8270_2.png) [@smailt](https://forum.djangoproject.com/u/smailt)\
**Post date:** [August 31, 2021, 3:33pm UTC](https://forum.djangoproject.com/t/deploy-django-with-debug-false/9489/7 "2021-08-31T15:33:59Z")

</div>

I solved a half of the issue and I can download the files by adding this code in urls.py

```auto
from django.views.static import serve
urlpatterns = [
    url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT, }),
    ...
    ]

```

but the styling still doesn’t work correctly!
