Задать вопрос
@RratavaA

Как устранить проблему с добавлением картинки через панель администрирования?

Когда сайт располагался на локальном сервере у меня получалось добавить картинку на сайт через панель администрирования. Но когда я выложил его на хостинг он начал выдавать ошибку при абсолютно идентичном действии.
Прошу помочь разобраться с проблемой.

Traceback:
File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
  575.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/contrib/admin/options.py" in change_view
  1557.         return self.changeform_view(request, object_id, form_url, extra_context)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/contrib/admin/options.py" in changeform_view
  1451.             return self._changeform_view(request, object_id, form_url, extra_context)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/contrib/admin/options.py" in _changeform_view
  1483.             if form.is_valid():

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/forms/forms.py" in is_valid
  179.         return self.is_bound and not self.errors

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/forms/forms.py" in errors
  174.             self.full_clean()

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/forms/forms.py" in full_clean
  376.         self._clean_fields()

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/forms/forms.py" in _clean_fields
  392.                     value = field.clean(value, initial)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/forms/fields.py" in clean
  578.         return super().clean(data)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/forms/fields.py" in clean
  148.         value = self.to_python(value)

File "/home/c/ca13594/django_3ku55//django/lib/python3.6/site-packages/django/forms/fields.py" in to_python
  611.         from PIL import Image

Exception Type: ModuleNotFoundError at /admin/shop/product/1/change/
Exception Value: No module named 'PIL'

6327083e90253837729126.png


admin.py
from django.contrib import admin
from .models import Category, Product


class CategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'slug']
    prepopulated_fields = {'slug': ('name',)}
admin.site.register(Category, CategoryAdmin)


class ProductAdmin(admin.ModelAdmin):
    list_display = ['name', 'slug', 'price', 'stock', 'available', 'created', 'updated']
    list_filter = ['available', 'created', 'updated']
    list_editable = ['price', 'stock', 'available']
    prepopulated_fields = {'slug': ('name',)}
admin.site.register(Product, ProductAdmin)

models.py
from django.db import models
from django.urls import reverse


# Create your models here.

class Category(models.Model):
    name = models.CharField(max_length=200, db_index=True)
    slug = models.SlugField(max_length=200, db_index=True, unique=True)

    def get_absolute_url(self):
        return reverse('shop:product_list_by_category',
                       args=[self.slug])

    class Meta:
        ordering = ('name',)
        verbose_name = 'category'
        verbose_name_plural = 'categories'

    def __str__(self):
        return self.name


class Product(models.Model):
    category = models.ForeignKey(Category, related_name='products',  on_delete=models.CASCADE, verbose_name='Категория')
    name = models.CharField(max_length=200, db_index=True, default='', verbose_name='Имя')
    slug = models.SlugField(max_length=200, db_index=True, verbose_name='Имя на английском')
    ca = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='Энергетическая ценность')
    cal = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='Жиры')
    call = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='Белки')
    calll = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='Углеводы')
    image = models.ImageField(upload_to='products/%Y/%m/%d', blank=True, verbose_name='Фото продукта')#Через эту форму я добавляю картинку
    description = models.TextField(blank=True, verbose_name='Описание')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='Цена')
    stock = models.TextField(blank=True, verbose_name='Необязательное описание')
    available = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    def get_absolute_url(self):
        return reverse('shop:product_detail',
                       args=[self.id, self.slug])

    class Meta:
        ordering = ('name',)
        index_together = (('id', 'slug'),)

    def __str__(self):
        return self.name
  • Вопрос задан
  • 47 просмотров
Подписаться 1 Простой Комментировать
Решения вопроса 1
AlexNest
@AlexNest
Работаю с Python/Django
Вам же написали - нет модуля PIL.
В чем проблема установить его?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы