Reputation: 95
I'm working with Django and I'm using a AdminLTE framework for the estilização, but, when I turn the DEBUG to False, the page shows with pure html.
settings.py
:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'saga.core',
'saga.subjects',
'saga.accounts',
'saga.tasks',
'saga.study_time',
'django_adminlte',
'django_adminlte_theme',
]
django_adminlte and django_adminlte_theme are the apps for the style framework.
Upvotes: 0
Views: 1833
Reputation: 1
When Debug = False , Django will not recognise the static files such as css and images. To make django aware you can follow the following steps :
pip install whitenoise
MIDDLEWARE = ['', 'whitenoise.middleware.WhiteNoiseMiddleware',]
STATIC_ROOT = BASE_DIR / 'production_files
. This will be used by django to create a folder to store all its static filespy manage.py collectstatic
For more information browse Here
Upvotes: 0
Reputation: 758
When DEBUG = True
Django will serve static and media files. When DEBUG = False
it will not. Therefore all of the js and css files will return a 404 error unless served. For a better of understanding of what is going on i would recommend reading https://docs.djangoproject.com/en/1.11/howto/static-files/ These static files may also be present in installed apps and not just within the project itself.
For local testing you can add the following to your urls.py
urlpatterns
:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
static
can be imported from from django.conf.urls.static import static
Further information can be found at https://docs.djangoproject.com/en/1.11/howto/static-files/#serving-files-uploaded-by-a-user-during-development
Further information regarding how to deploy static files in production can be found at https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/
Upvotes: 1