开发者

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 %}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜