Шаблоны DJANGO не обмениваются статическими файлами

В настоящее время у меня возникла проблема. У меня есть два шаблона django:cart.html и index.html. В cart.html есть связанный файл javascript. Оба этих файла должны обращаться к статическим файлам в папке static. Проблема в том, что когда я пытаюсь получить доступ к статическим файлам из связанного файла javascript cart.html, он выдает следующую ошибку: [15/Aug/2022 20:14:40] "GET /cart/images/fruits/Kornknacker.jpg HTTP/1.1" 404 2419. Вот мои настройки: STATIC_URL = 'static/'

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

Вот структура проекта: Project

Вот файл javascript:

{% load static %}
function loadCart() {
    let productsSection = document.getElementById("products_section");
    productsSection.innerHTML = '';
    let productHTML = '';
    let totalPrice = 0;
    let cartItems = JSON.parse(localStorage.getItem('cart'));
    if (cartItems && cartItems.length > 0) {
        for (let item of cartItems) {
            totalPrice = totalPrice + (item.quantity * item.price);
            productHTML = productHTML + `
        <div class="product-card" data-name="${item.itemName}" data-price="${item.price}" data-id="${item.itemId}">
        <div>
            <img src="{%static '/images/fruits/${item.itemName}.jpg'%}" alt="FRUIT" width="180">
        </div>
        <h3>
        ${item.itemName}
        </h3>
        <div>
            Anzahl: ${item.quantity}
        </div>
        <div>
            Preis: ${item.quantity * item.price}€
        </div>
    </div>
        `;
        }
        document.getElementById("total_price_container").style.display = 'block';
        document.getElementById("total_price").innerHTML = totalPrice;
        document.getElementById("no-products_section").style.display = 'none';
        document.getElementById("checkout-section").style.display = 'flex';
        document.getElementById("order-process_section").style.display = 'none';
        productsSection.innerHTML = productHTML;
    }
    else {
        document.getElementById("no-products_section").style.display = 'block';
        document.getElementById("checkout-section").style.display = 'none';
        document.getElementById("total_price_container").style.display = 'none';
    }
};
loadCart();

document.getElementById('checkout_cart').addEventListener('click', function () {
    console.log(localStorage);
    localStorage.removeItem('cart');
    document.getElementById("products_section").innerHTML = '';
    document.getElementById("order-process_section").style.display = 'block';
    document.getElementById("checkout-section").style.display = 'none';

})
document.getElementById('clear_cart').addEventListener('click', function () {
    localStorage.removeItem('cart');
    loadCart();
})

Вот структура проекта: Project

""" Настройки Django для проекта SemmelBrothers.

Создано командой 'django-admin startproject' с использованием Django 4.1.

Для получения дополнительной информации об этом файле см. https://docs.djangoproject.com/en/4.1/topics/settings/

Полный список настроек и их значений см. https://docs.djangoproject.com/en/4.1/ref/settings/. """

проблема в том, что django не может найти (404) "Kornknacker.jpg" в

"static/cart/images/fruits/Kornknacker.jpg"

Но вам, вероятно, следует указать на

"static/images/fruits/Kornknacker.jpg"

если это так, попробуйте я не уверен, что это действительно сработает 😂😂:

<img src="{%static '/../images/fruits/${item.itemName}.jpg'%}" alt="FRUIT" width="180">
Вернуться на верх