@mugbya
view.py
def home(request):
tags = json.dumps(Tag.tag_list.get_Tags())
return render_to_response('blog/index.html',
locals(), #它返回的字典对所有局部变量的名称与值进行映射。
context_instance=RequestContext(request))
Template页面
<script type="text/javascript">
/*!
* Create an array of word objects, each representing a word in the cloud
*/
//var list=[["Java", 8], ["Android", 0], ["数据库", 1], ["算法", 0]];
var list = {{ tagCloud|safe}};
var word_array = new Array();
var tag = {{ tags|safe }};
//tag = ["Java","Android","数据库","算法"]
for(i in list)
{
var temp = list[i][0];
for(var j = 0;j < tag.length;j++)
{
if(tag[j] == temp)
word_array.push({text:list[i][0],weight:list[i][1],link:"{% url 'tagDetail' tags.j %}"});
}
}
//word_array.push({text:list[i][0],weight:list[i][1],link: "http://www.tmackan.com/articleTag/" + temp});
/*var word_array = [
{text: "Lorem", weight: 15},
{text: "Ipsum", weight: 9, link: "http://jquery.com/"},
{text: "Dolor", weight: 6, html: {title: "I can haz any html attribute"}},
{text: "Sit", weight: 7},
{text: "日了", weight: 15}
// ...as many words as you want
];*/
$(function() {
// When DOM is ready, select the container element and call the jQCloud method, passing the array of words as the first argument.
$("#example").jQCloud(word_array);
});
</script>
urls.py
url(r'^articleTag/(?P<tag>\w+)/$', 'article.views.tagDetail', name="tagDetail"),#每个标签页下面的文章