Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Django, how can I use project wide static files?

Tags:

django

At the moment I have

myproject/app1

And I am adding a second app in and I wish to share some common JS and CSS

I have moved my static files from

myproject/app1/static

to

myproject/static

What configuration changes do I have to make for the applications to recognize the new location? I don't remember ever setting the directory initially I think it just worked out of the box

like image 926
Hoa Avatar asked Dec 06 '25 14:12

Hoa


1 Answers

From Django [1.11] Docs:

Your project will probably also have static assets that aren’t tied to a particular app. In addition to using a static/ directory inside your apps, you can define a list of directories (STATICFILES_DIRS) in your settings file where Django will also look for static files.

Add to settings.py:

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

Assuming you are using django.contrib.staticfiles app.

like image 163
Dušan Maďar Avatar answered Dec 08 '25 03:12

Dušan Maďar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!