0

when i am on my local host the css is loading but when i am on server then it is not and i am not using any static files in my project and debug is also set to False

I have tried setting debug = False and collect static files.

Arjun
  • 1
  • Are u using nginx or any other web server before django – Vinay Vishwakarma Jun 26 '23 at 05:42
  • 1
    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 Jun 26 '23 at 07:00

1 Answers1

0

If the static files are not loaded you may miss one of these steps:

  1. define STATIC_URL and STATIC_ROOT in settings.py. for example:
STATIC_URL = '/static/' 
STATICFILES_DIRS=(os.path.join(BASE_DIR,'media/assets/'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  1. define static in urls.py. for example
from django.contrib import admin
from django.conf.urls.static import static
from django.urls import path, include
from django.conf import settings

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('api_app.urls')),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \
    + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  1. Collect static files in the defined static directory:
python manage.py collectstatic
  1. check your server's public directories.

if you are using some shared host as your project server keep in mind that the static files should be in a public directory(like public_html) to be reachable by Django.

Saeed Ramezani
  • 462
  • 6
  • 20