The urls.py
file:
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
The settings.py
file:
STATIC_URL = '/web/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = '/home/domain.com/public_html/web/public/static'
I am using cyberpanel with openlightspeed server with contex:
context / {
type appserver
location /home/domain.com/public_html/web
binPath /usr/local/lsws/fcgi-bin/lswsgi
appType wsgi
startupFile web/wsgi.py
envType 1
env LS_PYTHONBIN=/home/domain.com/public_html/bin/pyhton
env PYTHONHOME=/home/domain.com/public_html/
}
My web app is not serving static files I am getting:
404 Not Found
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi there,
Here’s a general approach you could try to diagnose and fix the issue:
Check the Paths: Make sure that the paths in your
settings.py
are correct and accessible by the web server.Configure OpenLiteSpeed to Serve Static Files: You’ll need to add a context for serving static files in your OpenLiteSpeed configuration. This will tell OpenLiteSpeed where to find the static files and serve them directly without going through your Django app.
You can add the following context to your OpenLiteSpeed configuration file or through the admin interface:
Make sure to adjust the paths as needed based on your directory structure.
Collect Static Files: Run the
collectstatic
command to make sure all your static files are in the correct location:Check Permissions: Ensure that the permissions are set correctly on the static files directory so that OpenLiteSpeed can read them.
Restart OpenLiteSpeed: Finally, you’ll need to restart OpenLiteSpeed to apply the changes:
Verify URLs: Verify that the URLs to your static files in your HTML templates are being rendered with the correct path based on your
STATIC_URL
setting.Best,
Bobby