图片未显示在模板中

我正在尝试在页面中添加图像,但我不断

AttributeError: 'Setting' object has no attribute 'image' 

我曾在同一项目的其他模型中使用过Images多次,但我不知道这里可能缺少什么

这是Models.py

class Setting(models.Model):
    title = models.CharField(max_length=60)
    about_text = RichTextUploadingField(verbose_name="About Us Text")
    about_image = models.ImageField(
        blank=True, upload_to='Marketing', verbose_name="About Us Image")

    def __str__(self):
        return self.title

    def get_image_url(self):
        return "%s/%s" % (settings.MEDIA_URL, self.image)

这是意见

def who_we_are(request):
    setting = Setting.objects.get()
    template = 'who_we_are.html'
    context = {'setting': setting}
    return render(request, template, context)

这是模板

{% extends "base.html"%}
{% block content %}
       <div class="view" style="background-image: url('{{ setting.get_image_url }}');></div>
      <div class="container pt-4">
        {{setting.about_text|safe}}
    </div>
{% endblock content %}
评论
  • 衮开、
    衮开、 回复
    • improve this

    • modify self.image to self.about_image in model

    def get_image_url(self):
            return "%s/%s" % (settings.MEDIA_URL, self.about_image)