Re: Problems displaying image objects in a Django template using a custom template tag? (coding included)
Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Problems displaying image objects in a Django template using a custom template tag? (coding included)
Hello, I think you should use something like alt="{{ object.title }}" /> in your template: you want to output images' url in your template, not the "object" itself. You'll find explanations in [1] and [2]. Regards [1] http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.storage [2] http://docs.djangoproject.com/en/dev/ref/files/file/#the-file-object -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Problems displaying image objects in a Django template using a custom template tag? (coding included)
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 %} {{ object.title }} {{ object.body }} {% 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 Everything works fine. The problems occur when its a model image being called. Any help fixing this issue is much appreciated -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.