0

I am programming a website powered by Django 1.6.3. Under news you always see a big story and on the side recent articles. Therefore, I used Bootstrap 3 and wrote a static html page serving my requirements.

Now I would like to program the logic behind this. I save all my files under static that consists of the folders css, fonts (from Bootstrap), img and js. The image folder has some subfolder e.g. news. To create a new entry on the news page I would like to open the admin page, add a news_entry and select one image that should be under the titel. How is it possible to include the image in the page? My approach was:

<img src="{% static {{ news.image_name }} %}" class="img-title">

Unfortunately I get an parsing error. Image_name is a property of my news model.

Nick Lehmann
  • 598
  • 1
  • 7
  • 25

1 Answers1

0

You need to access the url attribute of your image_name.

Try:

<img src="{{ news.image_name.url }}" class="img-title">

Similar question here.

Community
  • 1
  • 1
Alex
  • 8,321
  • 1
  • 34
  • 30
  • No, this doesn't work. I got an error message saying: Could not parse the remainder: '{{' from '{{'. – Nick Lehmann Apr 29 '14 at 15:49
  • Edited. Take out the `static` url tag. Note that ImageFields are generally saved under your `MEDIA_ROOT`, not your `STATIC_ROOT`. Regardless, you don't need a media or static tag in template. – Alex Apr 29 '14 at 15:54