Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht
{% 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>

                  &nbsp; 
                  
                  <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>
                  
                  &nbsp;

                  <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?

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.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.