Django MEDIA_URL and MEDIA_ROOT

前端 未结 13 1094
天命终不由人
天命终不由人 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:40

    For Django 1.9, you need to add the following code as per the documentation :

    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)
    

    For more info, you can refer here : https://docs.djangoproject.com/en/1.9/howto/static-files/#serving-files-uploaded-by-a-user-during-development

    0 讨论(0)
提交回复
热议问题