Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make two directories static in django

Tags:

python

django

I have two directories. static contains javascript and css files. In settings I wrote STATIC_URL = '/static/' so they are included correctly.

But also I have folder images which has pretty many images. My question how can I make folder images also static, because I can't copy into into static.

Thank you.

like image 475
Andrew Fount Avatar asked Aug 26 '13 14:08

Andrew Fount


Video Answer


2 Answers

I wanted to add a static directory called uploads. I tried settings.py first, but it didn't work. However, I managed to turn uploads into a secondary static URL by adding this line to the file urls.py:

url(r'^uploads/(?P<path>.*)$', static.serve, {'document_root': settings.BASE_DIR + "/uploads"}),

If you get into trouble importing static.serve, this is the line you need to import it:

from django.views import static
like image 191
Roddy P. Carbonell Avatar answered Oct 15 '22 10:10

Roddy P. Carbonell


it looks like STATICFILES_DIRS can take multiple paths:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
    '/var/www/static/',
)
like image 28
dm03514 Avatar answered Oct 15 '22 11:10

dm03514