Serket
Serket

Reputation: 4485

Django templating error: Could not parse the remainder

I cannot figure out the problem with my templating. When. I tell it to render the dictionary, it does so successfully, but when I try taking out information from its keys, it returns this error: Could not parse the remainder. Here is the HTML:

{% extends 'template.html' %}

{% block title %}Cart{% endblock %}

{% block head %}
<script type="text/javascript">
  <!-- Script for product div styling -->
</script>
{% endblock %}

{% block body %}
  <div class="shop">
    <h1 class="header">Cart</h1>
    <table>
      <tr>
        <th>Product Name</th>
        <th>Topping 1</th>
        <th>Topping 2</th>
        <th>Topping 3</th>
        <th>Price</th>
      </tr>
    {% for item in productlist %}
      <tr>
        {% if item["product_name"] == True %}
          <td>Large {{item["product_name"]}}</td>
        {% else %}
          <td>{{item["product_name"]}}</td>
        {% endif %}
        <td>{{item["topping1"]}}</td>
        <td>{{item["topping2"]}}</td>
        <td>{{item["topping3"]}}</td>
        <td>{{item["price"]}}</td>
      </tr>
    {% empty %}
      <h3>Your cart is empty</h3>
      Add products to the cart through the <a href="{% url 'mainindex' %}">menu</a> page.
    {% endfor %}
    </table>
  </div>
{% endblock %}

If you need me to add the backend, I'd be happy to do so. Thanks

Upvotes: 0

Views: 215

Answers (1)

user13826290
user13826290

Reputation:

In django templates, a lot of syntax are not allowed. For example, the syntax like item["topping1"] is invalid. Instead, you can write it this way — item.topping1. Even if you are passing in an dictionary, this is the right syntax in the django templates.

{% block head %}
<script type="text/javascript">
  <!-- Script for product div styling -->
</script>
{% endblock %}

{% block body %}
  <div class="shop">
    <h1 class="header">Cart</h1>
    <table>
      <tr>
        <th>Product Name</th>
        <th>Topping 1</th>
        <th>Topping 2</th>
        <th>Topping 3</th>
        <th>Price</th>
      </tr>
    {% for item in productlist %}
      <tr>
        {% if item.product_name %}
          <td>Large {{item.product_name}}</td>
        {% else %}
          <td>{{item.product_name}}</td>
        {% endif %}
        <td>{{item.topping1}}</td>
        <td>{{item.topping2}}</td>
        <td>{{item.topping3}}</td>
        <td>{{item.price}}</td>
      </tr>
    {% empty %}
      <h3>Your cart is empty</h3>
      Add products to the cart through the <a href="{% url 'mainindex' %}">menu</a> page.
    {% endfor %}
    </table>
  </div>
{% endblock %}

Upvotes: 1

Related Questions