【问题标题】:Error when using Tag Cloud in Django在 Django 中使用标签云时出错
【发布时间】:2009-12-06 07:42:24
【问题描述】:

有我的代码:

{% load tag_cloud %}
{% tag_cloud_for_model blog.Entry as tags with steps=6 min_count=1 distribution=log %}
{% for tag in tags %}
    <span class="tag-{{tag.font_size|add:"1"}}"><a href="/blog/tag/{{tag.name|slugify}}/">{{tag.name}}</a></span> 
{% endfor %}

一切看起来都很正常,直到我在 6 个不同的条目中有 6 个标签“django”。报错如下:

TemplateSyntaxError at /blog/tags/
...
Caught an exception while rendering: invalid literal for int():
...
ValueError: invalid literal for int():

【问题讨论】:

标签: django django-templates


【解决方案1】:

对您提到的标记模块一无所知,我只能猜测问题出在{{tag.font_size|add:"1"}} 调用上。我认为您的 tag.font_size 之一的值不是数字...是否有可能某些值是 None 或非数字字符?

找出答案的一种方法是暂时删除 |add:"1" 并查看生成的 HTML 以查看正在呈现的内容...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多