Django MEDIA_URL and MEDIA_ROOT

前端 未结 13 1107
天命终不由人
天命终不由人 2020-11-22 11:36

I\'m trying to upload an image via the Django admin and then view that image either in a page on the frontend or just via a URL.

Note this is all on my local machine

13条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 12:35

    Please read the official Django DOC carefully and you will find the most fit answer.

    The best and easist way to solve this is like below.

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

提交回复
热议问题