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.
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.
If the static files are not loaded you may miss one of these steps:
- define
STATIC_URL
andSTATIC_ROOT
insettings.py
. for example:
STATIC_URL = '/static/'
STATICFILES_DIRS=(os.path.join(BASE_DIR,'media/assets/'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- define
static
inurls.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)
- Collect static files in the defined static directory:
python manage.py collectstatic
- 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.