简体   繁体   English

使用Django的ImageField检索上传的图像

[英]retrieving uploaded images with django's ImageField

this is the code in my models file: 这是我的模型文件中的代码:

from django.db import models

class Studio(models.Model):
    .....
    .....
    metroimage = models.ImageField(upload_to='images', blank=True)

this is the code on the template file: 这是模板文件上的代码:

 {% for place in studio %}
            .....
            .....
                    <img class="metro" src="{{ place.metroimage.url }}"><b>{{ place.metro }}</b><br>

                {% endif %}

but when the page displays i get this (this is source-code) 但是当页面显示我得到这个(这是源代码)

        .....
        .....     
                    <img class="metro" src="/http://momo.webfactional.com/media/images/m3.png"><b>Zara</b><br>

what's with the forward slash before http? http前面的正斜杠是什么? i can't get the uploaded image to display... 我无法显示上传的图片...

我想您的MEDIA_URL设置(在settings.py中)应归咎于多余的斜线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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