Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:40:25+00:00 2026-05-17T19:40:25+00:00

I have the following code that fails to display object images. But displays normal

  • 0

I have the following code that fails to display object images. But displays normal images fine.

My Model

class News(models.Model):
title-----------
image = models.ImageField(upload_to='images')
body------------

Template tag coding

from django import template
register = template.Library()
from ----.models import ---

def funct(num):
myobjects = News.objects.all()[:num]
return {'objects': myobjects}
register.inclusion_tag('news/template.html')(funct)

template coding

{% for object in objects %}
<li>{{ object.title }}</li>
<li><img src="{{ MEDIA_URL }}images/{{ object.image }}" alt="image" /></li>
<li>{{ object.body }}</p></li>
{% endfor %}

This code outputs all the variable information such as title and body in a list however it does not display the associated image. I have tried numerous variations on this code with no success. This is strange because when an image is called from the image folder in the following manner

<img src="{{ MEDIA_URL }}images/star.jpg" />

Everything works fine. The problems occur when its a model image being called.
Any help fixing this issue is much appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:40:26+00:00Added an answer on May 17, 2026 at 7:40 pm

    This has nothing to do with the custom template tag. If you looked at the source for the rendered page, you would see that {{ object.image }} does not output the URL for the image. You need to use {{ object.image.url }}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application with legacy code that relies on prototype, but we've found
I have following code I want to test: public class MessageService { private MessageDAO
I have tried to run the following code, as a proof of concept, and
I currently have an application that calls creates and displays charts from various objects'
I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf(Enter
I have the following code. When I call remove, I pass in a proxy
Let's say that I have the following HTML for a text box on an
At the top of my code for the form I have the following statements
In the about_symbols.rb Ruby Koan (https://github.com/edgecase/ruby_koans), I have the following code: RubyConstant = What
I have a set of cucumber tests that normally run fine against our site.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.