0

ive set my STATIC_ROOT dir in my settings.py. The shell print the path right where the files are located. But on rendering template on /comp/xyz the static files wont be loaded.

http://127.0.0.1:8000/static/js/jquery.min.js

This is the link rendered by STATIC_URL. its right. But no files.

>>> print(settings.STATIC_ROOT)
/home/mandaro/django/comp/static/
>>> 

there are all my staticfiles. So when i insert {{ STATIC_ROOT }}css/jquery.min.js on my templates. Why is this not working? Any some idea?

oranj33
  • 123
  • 1
  • 4
  • 11

1 Answers1

0

you should really read the documentation about serving static files.

Anyway probably you must add something like this in your urls:

from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

if settings.DEBUG:
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)

EDIT:

After your edit I saw that you are using {{ STATIC_ROOT }} instead of {{ STATIC_URL }} , is that a typo? Also I really advice you to switch to the {% static %} template tag, that because it is more portable with different storages.

DRC
  • 4,898
  • 2
  • 21
  • 35
  • i read it yes. but i dont need the media_root. neither i plan to go in production. so i need to learn it first. easy and clean. why is it not working? – oranj33 Dec 08 '14 at 01:55
  • @oranj33 I should point out that only the last line deals with media files – DRC Dec 08 '14 at 01:58
  • yes i see though :) and i appreciate it. but whats the reason the files didnt gonna be shown? btw. i gonna try it – oranj33 Dec 08 '14 at 02:01
  • @oranj33 as I said the reason is there in the documentation, in the box titled `Serving the files` – DRC Dec 08 '14 at 02:02