Делаю интернет магазин на django. Пытаюсь добавить фотографии товаров,но django почему то не видит их. Помогите в чем может быть проблема
Такая ошибка, хотя по данному пути есть картинки
вот файл settings.py
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
'../static/products/media/product_images/',
)
вот файл models.py
from django.db import models
# Create your models here.
class Product(models.Model):
name = models.CharField(max_length=70, blank=True, null=True, default=None)
price = models.DecimalField(max_digits=10, decimal_places=2, default=0)
description = models.TextField(blank=True, null=True, default=None)
short_description = models.TextField(blank=True, null=True, default=None)
is_active = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __str__(self):
return "%s, %s" % (self.price ,self.name)
class Meta:
verbose_name = 'Товар'
verbose_name_plural = 'Товары'
class ProductImage(models.Model):
product = models.ForeignKey(Product, blank=True, null=True, default=None, on_delete=models.CASCADE)
image = models.ImageField(upload_to='static/media/product_images/')
is_active = models.BooleanField(default=False)
is_main = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __str__(self):
return "%s" % self.id
class Meta:
verbose_name = 'Фотография'
verbose_name_plural = 'Фотографии'
вот шаблон html
{% extends 'online_shop/base.html' %}
{% load static %}
{% block content %}
<section>
<div class="top-section">
<img src="{% static 'img/clem.png' %}" class="img-fluid">
</div>
</section>
<section>
<div class="container">
<div class="row">
{% for product_image in product_images %}
<div class="col-lg-3">
<div class="product-item">
<div>
<img src="{{product_image.image}}" alt="" class="img-fluid">
</div>
<h4>{{product_image.product.name}}</h4>
<p>{{product_image.product.description|truncatechars_html:80 }}</p>
<div class="price">
{{product_image.product.price}} ГРН
</div>
<div class="add-to-card">
<button class="btn btn-success">
Добавить в корзину
</button>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
{% endblock content %}
Главный файл urls.py
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('online_shop.urls', namespace='online_shop')),
path('', include('products.urls', namespace='products')),
path('', include('orders.urls', namespace='orders')),
]
Вот urls моего приложения
from django.urls import path
from . import views
app_name = 'online_shop'
urlpatterns = [
# Home
path('', views.home, name='home'),
# Landing page
path('landing', views.index, name='index'),
]
urls.py
покажите