'NoneType' object has no attribute 'src'

313 views Asked by At

If I'm not wrong, I think this error mean I'm trying to display that doesn't exist. But I've provided the content, I don't know why I get this error. I'll explain in detail: I'm using django-ckeditor, and when I try to post image and text, they are grouped as content. And I'm trying to use image only to thumbnail it to the front page, separate from the content. So I'm using python goose to extract that image from content. in models.py

class Post(models.Model):
    content = RichTextUploadingField(config_name='default')
    @property

    def thumbnail(self):
        g = Goose()
        thumbnail = g.extract(raw_html=self.content).top_image.src
        return thumbnail

in html

<img src="{{ post.thumbnail }}" />

The error dissapears if I do def thumbnail(self, content) (and nothing gets displayed) but I shouldn't do that since I'm extracting from Post model, and that content which is self.content.

0

There are 0 answers