简体   繁体   中英

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 :

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),) . 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. That's why the date filter doesn't work.

You should check that c.start_date is a date, because it looks like it's a tuple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM