Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap does not be set to Django app

Bootstrap does not be set to my Django app.In google console,Failed to load resource: the server responded with a status of 404 (Not Found) bootflat.min.css error happens.I wrote in settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG =True

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

STATICFILES_DIRS = [os.path.join(BASE_DIR,'bootflat.github.io'), ]

in PythonServer_nginx.conf

server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name MyServerIPAdress; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /home/ubuntu/PythonServer/PythonServer/accounts/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/ubuntu/PythonServer/uwsgi_params; # the uwsgi_params file you installed
    }
}

I do not know why Bootstrap does not be set to my Django app.I run command python manage.py collectstatic but no error happens.How should I fix this?What should I write it?

like image 698
user8817674 Avatar asked Dec 19 '17 14:12

user8817674


2 Answers

I assume the project works fine in local, this problem occurs only when you use nginx. If that is the case probably the path you mentioned in the nginx config for location /static is wrong, try getting the absolute path to the static folder from the server and see.

like image 200
doubleo46 Avatar answered Sep 29 '22 23:09

doubleo46


I have no way to test my answer for obvious reason, but your STATICFILES_DIRS and STATIC_ROOT don't match. If you change your STATICFILES_DIRS to [os.path.join(BASE_DIR,"/static/"),'https://bootflat.github.io'], it might work. I suggested so because it doesn't make sense to me to os.path.join a local path with a public URL.

like image 41
Mia Avatar answered Sep 30 '22 00:09

Mia