-1

I want to publish my django project but when is change my settings.py "debug = False" static files are not loaded ! here is my settings.py

MEDIA_URL = '/media_files/'
STATIC_URL = '/static_files/'

MEDIA_ROOT = '/home/domain/public_html/static_cdn/media_root'
STATIC_ROOT = '/home/domain/public_html/static_cdn/static_root'

also I used "python manage.py collectstatic" command and it created folder in public_html

Mayti
  • 1
  • 2
  • See the django documentation on serving static files. https://docs.djangoproject.com/en/4.0/howto/static-files/deployment/ – AKX Jul 12 '22 at 09:33
  • 1
    Django is not supposed to serve static and media files on prod (with debug=false). Docs are pretty clear about that. Configure nginx or other webserver to serve those files. – Ivan Starostin Jul 12 '22 at 09:58
  • 1
    Does this answer your question? [Why does DEBUG=False setting make my django Static Files Access fail?](https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail) – Ivan Starostin Jul 12 '22 at 09:59
  • 1
    Please *don't*. While there *is* a way to circumvent the debug restriction, it is a (very) *bad* idea to do so. Django is *not* designed to serve files that do not change (this can be optimized through caching, etc.), and it is likely unsafe as well (in the sanse that one might try to access `/media/../../../code/secret.py` for example). – Willem Van Onsem Jul 12 '22 at 10:03

1 Answers1

0

i tried many ways but this is worked for me: for Media files Create a symlink of media folder to public_html in terminal:

$ ln -s ~/project_path/media/ public_html/media

for static files make symlink in terminal or just copy them to public_html folder.