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 ))