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?

2
  • is it the debug webserver? are you using staticfiles_urlpatterns to serve those? Commented Dec 8, 2014 at 1:45
  • youp. debug webserver. no staticfiles_urlpatterns. only a STATIC_ROOT and STATIC_URL. Commented Dec 8, 2014 at 1:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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 I should point out that only the last line deals with media files
yes i see though :) and i appreciate it. but whats the reason the files didnt gonna be shown? btw. i gonna try it
@oranj33 as I said the reason is there in the documentation, in the box titled Serving the files

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.