Accessing “Media” files in Django

前端 未结 7 2222
日久生厌
日久生厌 2020-12-02 03:54

I\'d like to love Django, but this business of static and media files in development environments is driving me nuts. Please rescue me from my stupidity.

I\'m on my

相关标签:
7条回答
  • 2020-12-02 05:01

    I am using Django 1.10. And my media folder is 'uploads' This is the configuration in my settings.py:

    MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
    MEDIA_URL = '/uploads/'
    

    And in the template I put the name o my MEDIA_URL before de object.name instead object.url like this:

        <img src="uploads/{{ imagen_identificativa.name }} " alt="{{imagen_identificativa}}">
    

    And it works for me. I hope this helps.

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