私はDjangoのテンプレートシステムにはまったく新しいです。 基本的に、私はコンテキスト内でdjangoに渡すリストのすべての内容を出力しようとしています。Djangoはテンプレートの中のリストの内容を表示します
私urls.pyの関連部分は、
url(r'^class/$', twobooks.classes.views.getAllInformation, {'template_name':'classes/displayBooks.html'}),
今here-である私の見解でgetAllInformationはようfollows-
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はfollows-
ようです<html>
<head>
<body>
<h1>Testing the class page backend</h1>
<ul>
{ % for author in authors|safe% }
<li>{{ author }}</li>
{ % endfor % }
</ul>
</body>
</html>
これはかなり簡単だと思いますが、何が起こっているのか分かりませんので、助けをお願いします。ありがとう!