【发布时间】:2011-09-12 10:31:03
【问题描述】:
我对 Django 的模板系统很陌生- 基本上,我试图打印出我在上下文中传递给 django 的列表的所有内容。
我的 urls.py 的相关部分在这里-
url(r'^class/$', twobooks.classes.views.getAllInformation, {'template_name':'classes/displayBooks.html'}),
现在,在我看来getAllInformation如下-
def getAllInformation(searchTerm,template_name):
nameAndNumberStore = modifySearchTerm(searchTerm)
url = modifyUrl(nameAndNumberStore)
soup = getHtml(url)
information = []
if (checkIfValidClass(soup,nameAndNumberStore)):
storeOfEditions = getEdition(soup)
storeOfAuthorNames = getAuthorName(soup)
storeOfBookNames = getBookNames(soup)
storeOfImages = getImages(soup)
information.append(storeOfAuthorNames)#REMEMBER this is a list of two lists
information.append(storeOfEditions)
return render_to_response(
template_name,
{'authors': storeOfAuthorNames},
)
和displayBooks.html如下-
<html>
<head>
<body>
<h1>Testing the class page backend</h1>
<ul>
{ % for author in authors|safe% }
<li>{{ author }}</li>
{ % endfor % }
</ul>
</body>
</html>
我认为这很简单,但我不确定发生了什么,所以我想寻求帮助 - 谢谢!
【问题讨论】:
标签: python django list templates