2

I am learning Django, and am trying to load a static css file. I have seen the other questions and read the docs, but I am still unable to see the problem. I am using Django 1.11.

Here is my urls.py:

from django.conf.urls import url 
from django.contrib import admin

from django.conf import settings
from django.conf.urls.static import static

from . import views

urlpatterns = [ 
    url(r'^$', views.index),
    url(r'^admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

My settings.py (only the part to do with static files):

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

STATICFILES_DIRS = ( 
    STATIC_ROOT,        
)

And the part of my template where I try and load the files: {% load static %}

Whenever I load the index.html template, the following error messages are displayed by my console:

core.js:5 Uncaught ReferenceError: define is not defined
    at core.js:5
localhost/:12 GET http://localhost:8000/static/css/homepage.css 
localhost/:11 GET http://localhost:8000/static/css/horz-navbar.css 
localhost/:10 GET http://localhost:8000/static/css/fonts.css 
localhost/:13 GET http://localhost:8000/static/css/style.css 

Here is the file directory structure:

mysite
  db.sqlite3
  manage.py
  mysite
    __init__.py
    settings.py
    urls.py
    views.py
    wsgi.py
  static
    admin
    css
      fonts.css
      horz-navbar.css
      homepage.css
      style.css
  templates
    index.html

So Django doesn't seem to recognize that the files exist, I have checked and made sure that the files exist on my computer, and I'm not sure if this was needed, but I have also run python manage.py collectstatic

Please tell me if you need anymore information.

2
  • Can you also paste the file directory structure in your question? Commented May 9, 2017 at 19:47
  • I have added a directory structure Commented May 9, 2017 at 19:59

2 Answers 2

3

Change your STATIC_ROOT into another name and then update your STATICFILES_DIR. Something like this:

STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
Sign up to request clarification or add additional context in comments.

Comments

2

Replace "{% static "css/fonts.css" %}" with "{% static 'css/fonts.css' %}". There's a mismatch between quotations.

1 Comment

I have done this, but the files still won't load. I get the same errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.