Veröffentlicht 28. August 20232 j {% include "store/base.html" %} {% load static %} {% block content %} <main class="pt-5"> <div class="container"> <h1 class="h5"> Warenkorb </h1> <hr> {% for item in cart %} {% with product = item.product %} <br> <div class="row mb-4 border product-item"> { <div class="col-md-3 col-lg-2 order-md-first bg-light"> <img class="img-fluid mx-auto d-block" width="200px" alt="Responsive image" src="{{product.image.url}}"> <!-- Product image --> </div> <div class="col-md-9 col-lg-10 ps-md-3 ps-lg-10"> <a href="" class="text-decoration-none text-reset"> <!-- Product get absolute url --> <h1 class="h5 pt-2"> {{product.title}}<!-- Product title --> </h1> </a> <div class="border"> <div class="col border-bottom"> <div class="row p-3"> <div class="col-6"> Produkt </div> <div class="col-6 text-end"><span class="h6 fw-bold">€ {{product.price}}<!-- Product price --> </span></div> </div> </div> <div class="col"> <div class="row p-3"> <div class="col-12"> <label for="select">Anzahl</label> <select id=""> <option selected> {{item.qty}} </option> <option value="">1</option> <option value="">2</option> <option value="">3</option> <option value="">4</option> </select> <br> <br> <button type="button" id="update-button" class="btn btn-primary btn-sm update-button"> Aktualisieren </button> <button type="button" id="delete-button" class="btn btn-danger btn-sm delete-button"> Löschen </button> </div> </div> </div> </div> </div> </div> {% endwith %} {% endfor %} <div class="col-12 text-end"> <div class="h6 fw-bold"> Gesamtsumme: € <div id="total" class="d-inline-flex"> <!-- cart.get_total --> </div></div> </div> </div> </main> {% endblock %} Hallo , ich versuche gerade mit Django eine Ecommerce Webseite zu programmieren und bekommen diesen Fehler. Kann mir jemand weiterhelfen?
28. August 20232 j Der Fehlermeldung "with' expected at least one variable assignment" deutet darauf hin, dass das {% with %}-Tag nicht korrekt verwendet wird. Das {% with %}-Tag in Django wird verwendet, um temporäre Variablen für den Inhalt eines Blocks oder einer Template-Variable zu definieren. In deinem Fall wird es verwendet, um die Variable product zu setzen, die auf item.product verweisen soll. {% with product = item.product %} Das Problem ist, dass die geschweiften Klammern {% %} nicht richtig geschlossen sind. Das gesamte Tag sollte so aussehen: {% with product=item.product %} Beachte, dass es keinen Raum zwischen product und = gibt, um sicherzustellen, dass das {% with %}-Tag korrekt interpretiert wird. Hier ist die korrigierte Version des entsprechenden Teils deines Codes: {% for item in cart %} {% with product=item.product %} <!-- ... Hier kommt der restliche HTML-Code ... --> {% endwith %} {% endfor %} Stelle sicher, dass du diese Anpassungen im gesamten Template an den entsprechenden Stellen vornimmst, an denen du das {% with %}-Tag verwendest.
28. August 20232 j Autor Das war die Lösung "Beachte, dass es keinen Raum zwischen product und = gibt, um sicherzustellen, dass das {% with %}-Tag korrekt interpretiert wird." Ich danke dir
Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.