我正在制作一个Django项目,一个商业目录。在这里,我在HTML页面中使用了分页。但我收到的错误是:
/ crawlerapp / search /中的KeyError 我遵循链接上给出的程序:https://pypi.python.org/pypi/django-pagination/1.0.5。
我使用分页的HTML代码是:
{% load pagination_tags %}
<html>
<head>
<title>{% block head_title %}SearchPage{% endblock %}</title>
</head>
<body>
<h1>{% block title %}The Blue Day, A Search Directory by Abhimanyu Choithramani{% endblock %}</h1>
{% block content %}
<div style="text-transform: uppercase;" id="network-bar">
<dl>
<dd>* <a href="http://127.0.0.1:8000/crawlerapp/">Homepage</a>
* <a href="http://127.0.0.1:8000/crawlerapp/contactus">Contact Us</a></dd>
</dl>
<dl>
<dd class="last" style="float: right;"><a href="http://127.0.0.1:8000/crawlerapp/" title="Blue Day Business Directory">Blue Day Business Directory</a></dd>
</dl>
<div class="network-bar-search"></div>
</div>
<div style="border-top: 1px dashed #6b88a5; margin: 10px;"></div>
<div style="padding: 0 10px 10px; position: relative;">
Search our <a href="http://127.0.0.1:8000/crawlerapp/">Business Directory</a> by entering a business type or name and just click on a Search.
</div>
<div style="position: relative;" id="headerSearchindex">
<form action='' method="GET">
<table style="width: 60%" border="0" cellpadding="1" cellspacing="0">
<tr>
<td class="hsTableTitleCell leftSpaced"> By category: </td>
<td class="hsTableTitleCell leftSpaced">Or by company name:</td>
<td style="width: 300px;"> </td>
</tr>
<tr>
<td class="hsTableBusinessCell leftSpaced"><input type="text" title="Business Category" placeholder="e.g Computer, Restaurants" name="what" autocomplete="off" value=""/></td>
<td class="hsTableCompanyCell leftSpaced"><input type="text" title="Company Name" placeholder="e.g Smith and Sons" name="who" value=""/></td>
<td class="hsTableSearchButtCell leftSpaced"><input name="search_action" type="submit" value="Search"/></td>
</tr>
</table>
</form>
</div>
{% autopaginate crawlerapp %}
<p>You searched for: <strong>{{ query }}</strong></p>
{% if crawlerapp %}
<p>Found {{ crawlerapp|length }} in this Category{{ crawlerapp|pluralize }}.</p>
<ul>
{% for Directory in crawlerapp %}
<li>Business Name: {{ Directory.Bussiness_name }}</li>
Description: {{ Directory.Description }}</br>
Contact Number: {{ Directory.Number }}</br>
Web_URL: {{ Directory.Web_url }}</br>
Address: {% for Adress in Directory.adress_set.all %}{{forloop.counter}}:- {{ Adress.adress_name }}</br>{% endfor %}
Photo: {% for Photos in Directory.photos_set.all %}{{ Photos.Photo_name }}</br>{% endfor %}</br></br>
{% endfor %}
</ul>
{% else %}
<p>No Business matched your search criteria.</p>
{% endif %}
{% paginate %}
</body>
<br><br><br><br><br><br><br><br>
<div id="footer"> © Abhimanyu Choithramani's <a href="http://127.0.0.1:8000/crawlerapp/" >The Blue Day</a> is a Business Search Directory.</div>
</div>
</div>
{% endblock %}
</html>
我是否正确使用变量名称进行分页? 如果是,问题出在哪里呢?
请帮帮我。
答案 0 :(得分:0)
另外,出于好奇。为什么选择这个第三方分页包而不是Django内置分页https://docs.djangoproject.com/en/1.5/topics/pagination/?