0

I'm trying to display a picture whose address is saved in the Django models attribute. As I know you need to enter in the fieldurl({% static movie.img %}) but it doesen't works. If only use url({% static 'img/default-movie.png' %}) it works.

That is my query sets from django shell:

In [21]: Movie.objects.first().img
Out[21]: <ImageFieldFile: ../MovieApp/movies/static/img/1202296.jpg>

P.S (I should mentioned, that these fields are in for loop {% for movie in movies %} )

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
FInch301
  • 21
  • 3
  • Why are your media files in the static folder? Keep a separate folder for static and media files. I assume your settings are at least configured properly (even if media and static files are in same folder) so you want to be writing `url({{ movie.img.url }})`. As an advice have separate media and static folders. – Abdul Aziz Barkat Mar 12 '21 at 15:17
  • 1
    Does this answer your question? [django html template can't find static css and js files](https://stackoverflow.com/questions/66437690/django-html-template-cant-find-static-css-and-js-files) – Ivan Starostin Mar 12 '21 at 15:26
  • if it is in media you should be able to do `` inside your loop – AMG Mar 12 '21 at 15:58

1 Answers1

1

It is not a static resource. This should do

src={{movie.img.url}}
Chymdy
  • 662
  • 4
  • 14