T
T
Tryggvi2018-06-15 17:10:56
Django
Tryggvi, 2018-06-15 17:10:56

Why doesn't django template see variables?

There are two methods in views that work approximately the same, one draws an order in the admin panel, and the other is the user’s personal account in it, I don’t pass the id in it, as in the first view, but other variables should work?

spoiler
#Админка
@staff_member_required
def AdminOrderDetail(request, order_id):
    order = get_object_or_404(Order, id=order_id)
    return render(request, 'admin/orders/order/detail.html', {'order': order})

#Личный кабинет
def account_view(request):
    order = Order.objects.filter(user=request.user)
    context = {
        'OrderItem': OrderItem,
        'Order': Order
    }
    return render(request, 'user_account.html', context)

Шаблоны:
<--Работает-->
<h1>Заказ {{ order.id }}</h1>
  <ul class="object-tools">
    <li>
      <a href="#" onclick="window.print()">Распечатать заказ</a>
    </li>
  </ul>
  <table width="100%">
    <tr>
      <th>Создан</th>
      <td>{{ order.created }}</td>
    </tr>
    <tr>
      <th>Заказчик</th>
      <td>{{ order.first_name }} {{ order.last_name }}</td>
    </tr>
    <tr>
      <th>E-mail</th>
      <td><a href="mailto:{{ order.email }}">{{ order.email }}</a></td>
    </tr>
    <tr>
      <th>Адрес</th>
      <td>{{ order.address }}</td>
    </tr>
    <tr>
        <th>Самовывоз</th>
        <td>{{ order.pickup }}</td>
    </tr>
    <tr>
        <th>Доставка</th>
        <td>{{ order.delivery }}</td>
    </tr>
    <tr>
      <th>Полная стоймость</th>
      <td>{{ order.get_total_cost }} руб.</td>
    </tr>
    <tr>
      <th>Статус</th>
      <td>{% if order.paid %}Оплачен{% else %}В ожидании оплаты{% endif %}</td>
    </tr>
  </table>

<--Не работает-->
<td>{{ order.id }}</td>
<td></td>
<td>{{ order.created }} </td>
<td>{{ order.get_total_cost }}</td>
<td></td>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question