Using date in the Django url templatetag
I am trying to build a date-based URL with Django's url template tag. I have a datetime object that I can display like so:
{{block|date:"F j Y"}}
However, when I use nearly the same syntax with the url templatetag, like so:
{% url me开发者_JAVA百科eting block|date:"Y" %}
I get an error -- it appears that the only thing passed to url is an empty string:
... Reverse for 'meeting' with arguments '(u'',)' and arguments ...
What might I be doing wrong?
The url
tag is a bit strange, and is very picky about its arguments. In particular, I don't think it evaluates any filters in its arguments.
You could try this:
{% with block|date:"Y" as blockyear %}{% url meeting blockyear %}{% endwith %}
精彩评论