django html file load image like `{{post.image.url}}`

445 Views Asked by At

models.py

class Post(models.Model):
    image = models.FileField(upload_to='note/static/note/')`

template

<img src={{note.image.url}}

error:

[14/May/2021 08:42:07] "GET / HTTP/1.1" 200 402

Not Found: /note/static/note/test.png

[14/May/2021 08:42:07] "GET /note/static/note/test.png HTTP/1.1" 404 2357

Did I do anything wrong?

1

There are 1 best solutions below

1
On

You will have to use the static template tag. Something like this

{% load static %}

<img src="{% static 'note/test.png'%}">

More to this can be found here https://docs.djangoproject.com/en/3.2/howto/static-files/