I do online shop on django. I'm trying to add photos of goods, but django for some reason does not see them. Help in what could be the problem

enter image description here Such an error, although there are pictures along this path

here is the settings.py file

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/', ) 

here is the models.py file

 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 = 'Фотографии' 

here is the html template

 {% 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 %} 

The main file 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')), ] 

Here are the urls of my application

 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'), ] 
  • show urls.py - m0nte-cr1st0

1 answer 1

In the main urls.py you need to add

 from django.conf import settings from django.conf.urls.static import static urlpatterns = [ # ... the rest of your URLconf goes here ... ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 

How to connect statics