TemplateSyntaxError:' with'预计至少有一个变量赋值

时间:2016-03-26 04:28:56

标签: python django django-templates

我正在尝试通过 GET 方法从模板发送会议对象的数据。为属性 meeting.date 提供一个更简单的别名,即日期我使用模板标记。但最终会出现TemplateSyntaxError。

urls.py

url(r'^meeting/$', meeting_display, name="meeting"),

views.py

def meeting_display(request):
    date = request.GET.get('date')

    ob_mem = memo.objects.get(subject='Meeting', rcv_username=username, date=date)
    ob_mee = memo.meeting_set.all()

    variables = RequestContext(request, {
        'meeting': ob_mee,
    })
    return render_to_response('meeting_display.html', variables)

meeting_display.html

{% for meeting in meeting_f %}
  <div class="list">
    {% with date = meeting.date %}
      <a href="{% url meeting %}?date={{date}}">{{ date }}:{{meeting.venue}}{{meeting.time}}</a>
    {% endwith %}
  </div>
{% endfor %}

1 个答案:

答案 0 :(得分:5)

=周围不应有空格。使用

{% with date=meeting.date %}

或旧语法

{% with date as meeting.date %}