[英]Why does Django pass a variable to a template like this?
I am adding a variable to a dictionary like this: 我在这样的字典中添加一个变量:
rr_context["start_date"] = c.start_date
And then I pass the dictionary to render_to_response
: 然后我将字典传递给render_to_response
:
return render_to_response(
rr_template,
rr_context,
context_instance=RequestContext(request))
Then in template I try to format it this way: 然后在模板中我尝试以这种方式格式化:
{{ start_date|date:"F" }}
But it returns nothing. 但它什么也没有回报。 I found the problem is for some reason Django passes a variable looking like this: (datetime.date(2011, 10, 7),)
. 我发现问题是由于某些原因Django传递了一个如下变量: (datetime.date(2011, 10, 7),)
。 I don't know why it happens this way. 我不知道为什么会这样。 I read the docs and I think I did it right way. 我阅读了文档,我认为我做得对。 What can be the issue? 可能是什么问题?
It seems that your start_date
is a tuple and not a single date value. 看来你的start_date
是一个元组而不是一个日期值。 That's why the date
filter doesn't work. 这就是date
过滤器不起作用的原因。
You should check that c.start_date
is a date, because it looks like it's a tuple. 您应该检查c.start_date
是否为日期,因为它看起来像是一个元组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.