Hi, i need help with my project as after deployment when viewing my site only html files without (css, js and images) below is the my settings.py on static files
STATIC_URL = '/static/'
STATICFILES_ROOT = [
os.path.join(BASE_DIR, '/static')
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
and below is the project static file arrangement
after running collecting static the files were placed at home directory inside a folder named nyawiguschool/statics
Your web server then needs to be configured to serve files from the static
url from the directory where the static files get placed.
okay, and how do i do that please show me an example
What web server are you using? (Nginx? Apache? Something else?) What is your configuration for your project for your server?
Hi, Same error occurred to me after adding js and images.
Try installing whitenoise middleware which serves static files without the server.
Pip/pip3 install whitenoise and include it in the installed apps
INSTALLED_APPS = [
'home',
'forum',
'ckeditor',
'whitenoise.runserver_nostatic',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles'
]
Include it in the middleware
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
'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',
]
Include the following in settings.py
STATICFILES_STORAGE = ('whitenoise.storage.CompressedManifestStaticFilesStorage')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
I am using it as a temporary fix. if you are using large number of media files you might have to find an alternative.
Let me know if it worked.
Thanks for reply however the solution dont seems to work on my side
Am using LiteSpeed server
Then we need to see your LightSpeed configuration file for your application.
Also, are you using OpenLightSpeed or the commercial version? Is this a host that you have full control over or a shared host?
There seems to be a pretty good guide at Running Python WSGI Apps with LSAPI – OpenLiteSpeed