A
A
ahmed_al_asad2016-11-01 03:11:23
Django
ahmed_al_asad, 2016-11-01 03:11:23

Why can't I display an image in Django?

I'm using Django 1.10.2, downloaded the Pillow module.
I can't display the image that I add through the "Django Administration". When adding a new book, I specify the cover of this book, the cover is added to the media / book_images folder as expected. But the site does not display the cover.
Anyway, here's my model:

class Books(models.Model):
    book_title = models.CharField(max_length=255, verbose_name="Названия книги")
    book_category = models.ForeignKey(Category, verbose_name="Категория книги")
    image = models.ImageField(
          upload_to="book_images",
          default="book_images/no-img.png",
          verbose_name="Обложка книги")
    number_of_pages = models.IntegerField(verbose_name="Количество страниц")
    author = models.CharField(max_length=255, verbose_name="Автор книги")
    published_author = models.ForeignKey(StaffLibrary, verbose_name="Автор публикации")
    published = models.DateTimeField(default=timezone.now, verbose_name="Дата публикации")
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

I take pictures like this:
{% for Book in Book_list %}
        <div class="book">
          <h2><a href="/books/{{ Book.id }}/">{{ Book.book_title }}</a></h2>
          <p class="image-center"><img src="{{ Book.image.url }}" alt=""></p>
          <hr>
          <p class="category">Категория: {{ Book.book_category}}</p>
          <p class="number_of_pages">Кол-во страниц: {{ Book.number_of_pages }}</p>
          <p class="author_of_book">Автор книги: {{ Book.author }}</p>
          <p class="published_author">Опубликовал: {{ Book.published_author }}</p>
        </div>
      {% endfor %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2016-11-01
@ulkoart

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

in urls

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question