1
In this article Django模板這樣與Mako的模板打印列表(Django的加入標籤)
{% for i in mylist %}
<tr>
<td>{{i.replist|join:"</td><td>" }}</td>
</tr>
{% endfor %}
打印列表mylist
這是一個對象。這可以在Mako中完成嗎?謝謝。
編輯
class Rep(db.Model):
author = db.UserProperty()
replist = db.ListProperty(str)
unique = db.ListProperty(str)
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
greeting = None
if user:
greeting = ("Welcome, %s! (<a href=\"%s\">sign out</a>)" %
(user.nickname(), users.create_logout_url("/")))
else:
greeting = ("<a href=\"%s\">Sign in or register</a>." %
users.create_login_url("/"))
L = []
s = self.request.get('sentence')
L.append(s)
L = L[0].split('\r\n')
def f2(L):
checked = []
for e in L:
if e not in checked:
checked.append(e)
return checked
Rep().replist = L
Rep().put()
mylist = Rep().all().fetch(10)
leng = len(mylist)
T = type(mylist)
self.response.out.write("Ttttt")
print [i for i in mylist]
L2 = f2(L)
x = len(L)
y = len(L2)
delta = x - y
for i in range(delta):
L2.append('')
q = Rep().all()
results = q.fetch(10)
db.delete(results)
template_values = {"s": s,
"L": L,
"L2": L2,
"x": x,
"y": y,
"greeting": greeting,
"mylist": mylist,
"leng": leng,
"T": T,
}
path = os.path.join(os.path.dirname(__file__), 'main.mako')
templ = Template(filename=path)
self.response.out.write(templ.render(**template_values))
我認爲他正在尋找替代'join'過濾器而不是'for'標籤。 – 2010-10-31 05:03:54
是的,我試圖呈現mylist這是列表對象:'mylist = Rep()。all()。fetch(10)'for循環只是呈現對象而不是對象的元素。 – Zeynel 2010-10-31 05:31:54
你能給我們一個你的列表項的例子嗎?如果它是模型返回的對象,則應該可以使用$ {i.member}來代替$ {someVar} – Scott 2010-10-31 05:35:16