python – Django how to output uploaded images


Hello, please help me with a problem.

I'm trying to make a blog in Django/Python , I want to display articles with pictures. The image is loaded by url from the admin, but not from the template, please tell me where to dig. Googled, Yandexil, found nothing working.

class Article(models.Model):
    title = models.CharField(max_length = 200)
    text = models.TextField()
    image = models.ImageField(blank=True)

    def __unicode__(self):
       return unicode(self.title)

from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', include(,
    url(r'^', include('blog.urls')),

]  + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


{% for article in articles %}
        <h1>{{ article.title }}</h1>
        <img src="{article.image}">
        <p>{{ article.text}}</p>
{% endfor %}

(Tried article.image.url crashes error)



<img src="{{ article.image.url }}">

But not

<img src="{article.image}">

When using {{ article.image.url }} , what error are you seeing?

Scroll to Top