B
B
bubaley2020-04-25 17:18:58
Django
bubaley, 2020-04-25 17:18:58

Why does django take static from outside the project folder?

Hello
I published django on hosting according to the hosting instructions (beget)
Hosting knocks on public_html where .htaccess is located, the app project is in the same folder
Accordingly, the static of the project is in app / static
But django does not want to take files from public_html / app / static . And if we shift the statics to public_html/static, then everything works fine.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = False
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

What could be the snag?
I have tried many things, but nothing helps.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
bubaley, 2020-04-28
@bubaley

As it turned out, indeed, it is better to publish on VDS. Because, often not all hostings allow you to set up a folder from where to get statics.
Since Django does not distribute static when DEBUG=False, it should be distributed by a web server, such as nginx

location /static {
    root /home/www/__your_aplication__;
    try_files $uri =404;
}
# из этой настройки запросы будут уходить в /home/www/__your_aplication__/static

STATIC_ROOT specifies the directory (identical to the path above) where django will collect statics using the collectstatic command.

D
Dr. Bacon, 2020-04-25
@bacon

Another "didn't read" the docks about statics, 1. it's not django that does it on prod, 2. with DEBUG = False, django does not distribute statics at all without a special directive.
Threat under django is better than VDS, so as not to depend on the hoster.

D
Dmitry Kopylov, 2021-11-11
@kabantver

In the .../public_html/ folder, you need to make a symlink to the static folder in your project.
In my version it looked like this:
************************/public_html [0] $ ln -s "path_to_static_folder_starting_from_public_html_folder"/static/ static
ls -la folders ..../public_html/:
618d293d42d0e134824891.png
In your case - *************/public_html[0] $ ln -s /app/static/ static

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question