Hi,
I completely stuck with displaying media files - 'ImageField' in my html. 
Static files are displayed ok. I've read the 'whole internet' that topic 
and still nothing. I'm working on mac OS Sonoma, Django 5.1.3, Python 3.11.

My Html:
<img class="fit-picturePr" src="{{miod.miody_foto.url}}">

My model:
miody_foto = models.ImageField(upload_to = 'miody_foto', blank=True, null=
True, default='miody_foto/spadz.jpg')

view:
def miody(request):

mymiody = Miody.objects.all().values()

template = loader.get_template('Produkty/miody.html')

context = {

'mymiody': mymiody,

}

return HttpResponse(template.render(context, request))


Projects url:

urlpatterns = [

path('', include('Pasieka.urls')),

path('', include('Galeria.urls')),

path('', include('Produkty.urls')),

path('admin/', admin.site.urls),

]

if settings.DEBUG: 

urlpatterns += static(settings.MEDIA_URL,

document_root=settings.MEDIA_ROOT)


Application:

urlpatterns = [

path('Produkty/miody/', views.miody, name='miody'),

path('miody/', views.miody, name='miody'),

]


Additionally, files are displaying properly in my admin:

class MiodyAdmin(admin.ModelAdmin):

def image_tag(self, obj):

return format_html('<img src="{}" style="max-width:200px; 
max-height:200px"/>'.format(obj.miody_foto.url)) # wyswietlane zdj miodu

image_tag.short_description = 'miody_foto'

list_display = ("rodzaj", "opis", "miody_foto", 'image_tag',)# 
'miody_foto.url', 'miody_foto.height', 'miody_foto.name',)

admin.site.register(Miody, MiodyAdmin)#, ImageAdmin)


Any help would be priceless.


helpless Ewa

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/django-users/79227829-8ca1-40a1-8117-1732f1658207n%40googlegroups.com.

Reply via email to