What are the differences of these three static url?
I am not sure if I am right, I am using the MEDIA_ROOT
to store my uploaded photos (via models.ImageField()
)
However, I created a JS script to my admin and in admin.py
. I defined the media as below:
....
class Media:
js = ('/admin/custom.js', )
and my settings.py
:
....
STATIC_ROOT = "/home/user/project/django1/top/listing/static"
and I added the custom.js
to STATIC_ROOT/admin/custom.js
, but it is not working. Throwing 404 not found error.
And then I change the STATIC_ROOT
to STATICFILES_DIRS
, and it works!!
....
STATICFILES_DIRS = "/home/user/project/django1/top/listing/static"
So, I am not understand what is going on here. In fact, I just don't understand what is the difference between STATIC_ROOT
and STATICFILES_DIRS
.
Currently I am testing Django in my machine via virtualenv, not deployed yet, is it the reason STATIC_ROOT
not working??
You can find these settings in the Django documentation. Here are my own definitions and quotations from the documentation:
MEDIA_ROOT
is the folder where files uploaded usingFileField
will go.STATIC_ROOT
is the folder where static files will be stored after usingmanage.py collectstatic
STATICFILES_DIRS
is the list of folders where Django will search for additional static files aside from thestatic
folder of each app installed.In your settings, you should have:
...where:
as defined in the default Django
settings.py
now.