2

I am trying to show an image but every time image is broken:

settings.py

MEDIA_ROOT = "media/"

models.py

image = models.ImageField(null=True, blank=True, upload_to='article_image/')

Template (presenter.html)

<img src="{{ art.image.path }}">

The path looks like this /home/mikemoix/IdeaProjects/vlad/media/article_image/aptitude_test1.gif

What can I do?

1
  • 2
    There are a couple things that might be the problem. First, to get the link version you need to use {{art.image.ur}], which will give you the link version, rather than {{art.image.path}}, which gives you the file system path. You also might need to change your MEDIA_ROOT to "/media/" -- but that would depend on what your file structure actually looks like Commented Apr 16, 2015 at 19:35

1 Answer 1

4

The correct way to link to an image is:

<img src="{{ art.image.url }}">

An ImageField is essentially stored as a FieldFile. See the docs for details.

Sign up to request clarification or add additional context in comments.

4 Comments

Its not work. Should i change MEDIA_ROOT or add MEDIA_URL? log: ...... "GET /article/getarticles/0/media/article_image/aptitude_test1.gif HTTP/1.1" 404 .......
@user3551959 Can you post both MEDIA_ROOT and MEDIA_URL lines in your settings.py?
I have MEDIA_URL = '/media/' MEDIA_ROOT = 'media/'
What do you see when you view the HTML source on your browser?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.