hash hash - 2 months ago 39
Python Question

static files not detected Django 1.10

Problem: javascript and css files doesn't load.

I am using Django 1.10, my

settings.py
file looks like this:

STATIC_URL = "/static/"

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]

STATIC_ROOT = os.path.join(BASE_DIR, "static_root")


I have my static files in the
static folder
and also have a static root, still the
js
,
css
not working
Why?

Answer

You need to specify it in urls.py file as well

# need these two additional imports
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
  ...
]

# add this extra line of code
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Have you done that?

Comments