我正在尝试通过 GET 方法从模板发送 session 对象的数据以进行查看。为了给属性 Meeting.date 一个更简单的别名,即 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 %}
最佳答案
=
周围不应有空格。无论使用
{% with date=meeting.date %}
或旧语法
{% with date as meeting.date %}
关于python - TemplateSyntaxError : 'with' expected with atleast one variable assignment,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36231619/