Home > database >  CSS Not Showing Up in Django with NGINX and uWSGI
CSS Not Showing Up in Django with NGINX and uWSGI

Time:06-13

This is my first real Django project and I am trying to configure it for production using NGINX and uWSGI. It is running on a Digital Ocean Ubuntu server. Everything is set up and working besides serving static CSS files. The strange thing about this is that its serving static images and JavaScript files fine, the only thing that isn't being served is the CSS.

This is what my site configuration file for NGINX looks like ('nebula' is the Ubuntu User and the name of the Django project):

# configuration of the server
server {
    server_name example.com www.example.com;
    charset     utf-8;
    # max upload size
    client_max_body_size 75M;
    # Django media and static files
    location /media  {
        alias /home/nebula/nebula/media;
    }
    location /assets {
        alias /home/nebula/nebula/assets;
    }
    # Send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/nebula/nebula/uwsgi_params;
    }
}

This is what my Settings.py file looks like:

BASE_DIR = Path(__file__).resolve().parent.parent

STATIC_URL = '/assets/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
STATIC_ROOT = os.path.join(BASE_DIR, "assets/")

STATICFILES_DIRS = ( os.path.join(BASE_DIR,'assets/'),)

This is what my base directory looks like (assets and static are the same, I duplicated it in an attempt to solve the issue):

assets      demo.py    media   nebula.sock       static  uwsgi_params
db.sqlite3  manage.py  nebula  nebula_uwsgi.ini  set     store

This is inside of 'assets/':

admin  css  images  jazzmin  js  vendor

CodePudding user response:

The location path for your static files in your nginx config should match your STATIC_URL setting

    location /assets {
        alias /home/nebula/nebula/assets;
    }

CodePudding user response:

Seems like there could be an issue here

Could you try Changing

STATICFILES_DIRS = ( os.path.join(BASE_DIR,'media/'),)

to

STATICFILES_DIRS = ( os.path.join(BASE_DIR,'assets/'),)
  • Related