B
B
birdy902014-08-19 21:47:46
Django
birdy90, 2014-08-19 21:47:46

Is it possible to put django static files directly into STATIC_ROOT?

Good evening.
I have a question that may be silly, but really tormenting me: all the manuals for static files in Django say that you need to use the collectstatic command to collect files in the folder specified in the settings in the STATIC_ROOT variable.
I don't understand where Django collects these files from. Aren't all the files immediately in some shared folder? I, maybe in my stupidity, put all the files in the media folder, neatly, on the shelves. Then I used MEDIA_ROOT, MEDIA_URL and everything worked. And now, after a break, I decided to figure out if this is correct. What is the fundamental difference between STATIC and MEDIA?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-08-19
@birdy90

STATIC_ROOT - directory where non-changeable files are stored. As a rule, this is the layout of the design, verification keys, and so on. The fact that the site developer has kept forever.
MEDIA_ROOT - Directory of user files. What users fill in (avatars, text files / archives), what the engine can generate itself (for example, the script steals pictures from another site and stores them here).

I don't understand where Django collects these files from.

There is a folder where the developer first drops static files. Paths are written to STATICFILES_DIRS . After applying collectstatic, the files are transferred (cloned) to the folder path to which is specified in STATIC_ROOT.
My version (1.6.)
import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(PROJECT_PATH, "media")
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_PATH, "static")
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(PROJECT_PATH, "dev_static"),
)

And yes, the most important thing. Yes! You can fold right away, Django will not be offended. But in the opposite direction, adding to STATICFILES_DIRS and not executing collectstatic, and then hoping to see the files in STATIC_ROOT, is impossible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question