预计至少有一个变量赋值

预计至少有一个变量赋值

本文介绍了TemplateSyntaxError: 'with' 预计至少有一个变量赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 GET 方法将 会议 对象的数据从模板发送到查看.为了给属性 meeting.date 一个更简单的别名,即 date,我使用了 with 模板标签.但它以 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()变量 = RequestContext(请求,{'会议':ob_mee,})return render_to_response('meeting_display.html', 变量)

meeting_display.html

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

{% 结束为 %}

解决方案

= 周围不应有空格.要么使用

{% with date=meeting.date %}

或旧语法

{% with meeting.date as date %}

I am trying to send the data of a meeting object from template to view via GET method. To give the attribute meeting.date a simpler alias i.e date I am using the with template tag. But it ends up with a 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 %}
解决方案

There should be no spaces around =. Either use

{% with date=meeting.date %}

or the old syntax

{% with meeting.date as date %}

这篇关于TemplateSyntaxError: 'with' 预计至少有一个变量赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:11