Lyagu  Michael
Lyagu Michael

Reputation: 45

Django not displaying images

Django not displaying image upload from admin, more then one day i try to fix it but no result can anyone help me.

settings.py

MEDIA_ROOT = 'D:/django_projects/BASE_DIR/media'
MEDIA_URL = '/media/' 

urls.py

...
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

models.py

...
image = models.ImageField(upload_to = 'media/', default = 'media/no-img.jpg')

index.html

...
<li> <img src="{{ MEDIA_URL }}{{ news.image }}" width=200 height =100 align="left" class="leftimg"/> 

Upvotes: 0

Views: 436

Answers (1)

Milosz
Milosz

Reputation: 36

Use this: {{ news.image.url }}

Upvotes: 2

Related Questions