Answer the question
In order to leave comments, you need to log in
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')
Answer the question
In order to leave comments, you need to log in
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
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.
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/:
In your case - *************/public_html[0] $ ln -s /app/static/ static
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question