开发者

Using date in the Django url templatetag

开发者 https://www.devze.com 2023-01-24 16:55 出处:网络
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:

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

精彩评论

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

关注公众号