Thanks to Ali's answer, For anyone with the same problem, here are the steps I've done.
Wish it would be helpful:
- Make sure your
settings.py
file contains these lines:
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
run python manage.py collectstatic
Edit your passenger_wsgi.py
and add these lines:
# ...
# Import WSGI of your project
# Project Static File Path
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/myapp')
SCRIPT_NAME = os.getcwd()
class PassengerPathInfoFix(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
from urllib.parse import unquote
environ['SCRIPT_NAME'] = SCRIPT_NAME
request_uri = unquote(environ['REQUEST_URI'])
script_name = unquote(environ.get('SCRIPT_NAME', ''))
offset = request_uri.startswith(script_name) and len(environ['SCRIPT_NAME']) or 0
environ['PATH_INFO'] = request_uri[offset:].split('?', 1)[0]
return self.app(environ, start_response)
application = PassengerPathInfoFix(application)
- If you deployed your Django project in a subfolder inside
public_html
and not in the public_html
directory (as mine), copy the static
folder to public_html
or create symbolic link using ln -s public_html/static/ public_html/subfolder/static/
(The point is the static
files only load from your domain/subdomain base directory) (maybe there is a better solution but this solved my problem)
So I moved the project to the base directory of my domain and it worked.