简体   繁体   中英

Django Media not showing with Debug False

I'm a beginner at Python, my settings.py:

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'theme', 'static'),
]

If I turn DEBUG to False,the staticfiles and mediafiles don't work, when i run devserver in insecure mode:

python manage.py runserver --insecure

The staticfiles works,but mediafiles(avatars) still doens't work.

my app installed way:

pip install misago

start path: /home/project/

Can someone help me? thanks.

Django with debug false, does not manage the statics and media files.

You need to:

  1. Add "statics root" and "media root" to your django settings.py file
  2. Use NGINX to manage statics file (see more info about deployment on django documentation)
  3. use "collect static" command to collect the static/media file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM