Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make STATICFILES_DIR same as STATIC_ROOT in Django 1.3?

I'm using Django 1.3 and I realize it has a collectstatic command to collect static files into STATIC_ROOT. Here I have some other global files that need to be served using STATICFILES_DIR.

Can I make them use the same dir ?

Thanks.

like image 902
WoooHaaaa Avatar asked Aug 28 '12 14:08

WoooHaaaa


People also ask

How do you handle static files?

To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express. The root argument specifies the root directory from which to serve static assets.

What does Django Collectstatic do?

collectstatic. Collects the static files into STATIC_ROOT . Duplicate file names are by default resolved in a similar way to how template resolution works: the file that is first found in one of the specified locations will be used. If you're confused, the findstatic command can help show you which files are found.

What is Static_url in Django?

STATIC_URL is simply the prefix or url that is prepended to your static files and is used by the static method in Django templates mostly. For more info, read this. STATIC_ROOT is the directory or location where your static files are deployed when you run collectstatic .


1 Answers

No. In fact, the file django/contrib/staticfiles/finders.py even checks for this and raises an ImproperlyConfigured exception when you do so:

"The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting"

The STATICFILES_DIRS can contain other directories (not necessarily app directories) with static files and these static files will be collected into your STATIC_ROOT when you run collectstatic. These static files will then be served by your web server and they will be served from your STATIC_ROOT.

If you have files currently in your STATIC_ROOT that you wish to serve then you need to move these to a different directory and put that other directory in STATICFILES_DIRS. Your STATIC_ROOT directory should be empty and all static files should be collected into that directory (i.e., it should not already contain static files).

like image 184
Simeon Visser Avatar answered Oct 05 '22 15:10

Simeon Visser