Tagcloud with XML

Source: Internet
Author: User

Tag: Django Python tag

Django background development adds a 3D Tag Cloud plug-in

3 In dtagcloudwithxml, the XML generation method is used to generate xml automatically without the need to manually modify the XML. Specifically, the xmlgenerator is rough, mainly because of the Database Import and environment variables in the previous article.

The Code is as follows:

#! /Usr/bin/Python
From XML. etree import elementtree
From XML. etree. elementtree import element, subelement, tostring
From XML. Dom import minidom
Import random
# From Django. conf import settings
From sys import path
Path. Extend (['/home/zoueswebsite', '/home/zoueswebsite/blog', '/home/zoueswebsite'])
Import OS
OS. Environ ['django _ settings_module '] = 'zoueswebsite. setting'
From blog. Models import *




Def prettify (ELEM ):
Rough_string = elementtree. tostring (ELEM, 'utf-8 ')
Parse_string = minidom. parsestring (rough_string)
Return parse_string.toprettyxml (indent = "")




Root = element ('tag ')


For num, value in enumerate (category. Objects. All ()):
Subelement (root, 'A', {'href ':'/category/'+ value. Alias,
'Class': "tag-link-" + STR (category. Objects. Count ()),
'Title': "2 topics ",
'Rel ': "tag ",
'Style': "font-size:" + STR (random. Uniform (10, 20) + "PT ;",
'Color': "0xff0099 ",
})
With open ('category. xml', 'w') as F:
F. Write (pretloads (Root ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.