#encoding=utf-8
#made by davidsu33
#2015-2-9
from django.template import Template,Context
from django.conf import settings
class Athlete:
name = ""
height= 0
weight = 0
def __init__(self, *arg):
"""
print("arg_couont=", len(arg))
print("arg_type=", type(arg[0]))
print("arg[0]=", arg[0])
print("arg[0].len=", len(arg[0]))
"""
if type(arg[0]) == list and len(arg[0]) == 3:
thelist = arg[0]
self.name = thelist[0]
self.height = thelist[1]
self.weight = thelist[2]
else :
raise Exception("Invalid Argument!!!")
def __str__(self):
return "name=%s, height=%d, weight=%d" % \
(self.name, self.height, self.weight)
if __name__ == "__main__":
html = """
<html>
<head>
<title>for test for </title>
</head>
<body>
<ul>
{% for athlete in althlete_list %}
<li>{{athlete.name}} ,{{athlete.height}}, {{athlete.weight}}</li>
{% endfor %}
</ul>
</body>
"""
settings.configure()
#name height weight
source = [
["zhangsan", 180, 100],
["lisi", 168, 60],
["wangwu", 175, 90],
]
athletes = []
for i in source:
athletes.append(Athlete(i))
for i in athletes:
print(str(i))
t = Template(html)
c = Context({"althlete_list": athletes})
r = t.render(c)
print("r=", r);
#save to disk file
file_path = "d:/test.html"
f = open(file_path, "w+")
assert(not f.closed)
f.write(r)
f.close()
#encoding=utf-8
#made by davidsu33
#2015-2-9
from