L
L
Lolo Penguin2020-02-28 07:50:46
Django
Lolo Penguin, 2020-02-28 07:50:46

Why doesn't static work after uploading to hosting?

What's wrong here?

STATIC_URL = '/static/'
# STATIC_ROOT = 'static'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    os.path.join(BASE_DIR, "meccano_print/static"),
    os.path.join(BASE_DIR, "prints/static"),
    os.path.join(BASE_DIR, "zels/static"),
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-02-28
@ledo02

1. You need to define STATIC_ROOT- Django copies files from STATICFILES_DIRS.
2. Decide in which directory you will keep the general project statics that are not related to any particular application. Write it in STATICFILES_DIRS.
3. No need to point to STATICFILES_DIRSspecific application directories - Django by default collects STATIC_ROOTeverything it finds in directories staticinside applications.
So the configuration could be like this:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static") # Изначально пустой каталог, куда Django соберёт всё при выполнении manage.py collectstatic
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static_dev"), # Каталог, куда вам нужно складывать статику проекта, не относящуюся к конкретному приложению
]

Plus, if you launch the site in via runserver, then you need to set up the distribution of statics in development mode . And don't forget to run manage.py collectstatic. Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question