我對Django的模板系統很新穎-基本上,我試圖打印出我傳遞給上下文中的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>
我認爲這很簡單,但我不確定發生了什麼事,所以我想請求一些幫助 - 謝謝!