0

I set my DEBUG variable to False in setting.py and deployed my project in cpanel,used collectstatic command but static files not loading.

setting.py

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
if DEBUG:
    STATICFILES_DIRS = [(
            BASE_DIR / 'static/')
    ]
    MEDIA_ROOT = os.path.join(BASE_DIR, "static_cdn", "media_root")

else:
    STATIC_ROOT = "/home/smartsbi/public_html/static"
    MEDIA_ROOT = "/home/smartsbi/public_html/media"

urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('home.urls')),
    path('blog/', include('blog.urls')),
    path('ckeditor/', include('ckeditor_uploader.urls')),
    path('', include('contact_us.urls')),
    path('', include('service.urls')),

]
if settings.DEBUG:
    # add root static files
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    # add media static files
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  • Does this answer your question? [Why does DEBUG=False setting make my django Static Files Access fail?](https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail) – Ivan Starostin Jan 28 '23 at 12:03
  • Django is not supposed to serve those files in Debug=false, your own code adds url patterns only when Debug=true, thus they don't get added when it is false - this is the code you posted. [Docs](https://docs.djangoproject.com/en/4.1/howto/static-files/deployment/#serving-static-files-in-production) are pretty clear: configure your webserver to serve static and media files on production. – Ivan Starostin Jan 28 '23 at 12:05

0 Answers0