jfk83
jfk83

Reputation: 810

Django global static files not loading

I want to have global static files and templates for all my apps. My apps also will have templates and static files It will look something like this:

I am loading my global files like these but it is not working.

{% load staticfiles %}

href="{% static  'bootstrap/css/bootstrap.min.css' %}"

and I get:

"NetworkError: 500 Internal Server Error - http://localhost:8000/static/bootstrap/css/bootstrap.min.css"

By the way I can access to my apps static but not the global, I debug the STATIC_ROOT and PROJECT_ROOT and they seem good.

PROJECT_ROOT ='C:\\webpages\\client_portal\\client_portal'

projectname]/                  <- project root 
├── [projectname]/              <- Django root
│   ├── __init__.py
│   ├── settings/
│   ├── urls.py
│   └── wsgi.py
├── apps/
│   └── __init__.py
│
├── manage.py
│
├── static/
│   └── GLOBAL STATIC FILES
└── templates/
    └── GLOBAL TEMPLATES

My settings.py looks like this:

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.join(PROJECT_ROOT, '/static')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, '/static'),
)

Upvotes: 0

Views: 1259

Answers (2)

matias perret cantoni
matias perret cantoni

Reputation: 11

I think your problem is that you have an unneeded forward slash in STATICFILES_DIRS. So change this:

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, '/static'),
)

to this:

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

Hope it helps, it worked for me in Django 2.0, without the need of using PROJECT_ROOT neither STATIC_ROOT.

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599846

STATIC_ROOT and STATICFILES_DIRS should not be the same. Create a different directory, eg staticfiles, to store your development static files and use that in STATICFILES_DIRS instead.

Upvotes: 1

Related Questions