Page not found 404 Django media files

后端 未结 4 1976
盖世英雄少女心
盖世英雄少女心 2021-01-31 15:26

I am able to upload the files to media folder( \'/peaceroot/www/media/\') that I have set up in settings.py as below

MEDIA_ROOT = \'/pe         


        
4条回答
  •  借酒劲吻你
    2021-01-31 16:09

    The better way for MEDIA_ROOT is,

    try to make media path dynamic will be easy when you shift your project.

    Settings.py

    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    
    
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
    MEDIA_URL = '/media/'
    

    urls.py

    from django.conf import settings
    from django.conf.urls.static import static
    
    urlpatterns = [
        # ... the rest of your URLconf goes here ...
    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    

    Look at this

    https://docs.djangoproject.com/en/dev/howto/static-files/

提交回复
热议问题