【问题标题】:Pagination works improper and creates error分页工作不当并产生错误
【发布时间】:2013-07-15 22:38:47
【问题描述】:

我正在制作一个 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;">&nbsp;</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"> &copy; 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>

我是否正确使用变量名进行分页? 如果是,那么问题出在哪里?

请帮帮我。

【问题讨论】:

  • 错误在您的代码中,而不是您的模板中,它会告诉您是哪一行导致了错误。请提供错误和代码。

标签: python django django-models django-templates django-views


【解决方案1】:

hmmmm,当我们不知道缺少什么键时,如果没有回溯,很难判断哪里出了问题。你有调试页面吗?这可能有助于我们弄清楚。

另外,只是出于好奇。为什么选择这个第三方分页包而不是Django内置分页https://docs.djangoproject.com/en/1.5/topics/pagination/

【讨论】:

猜你喜欢
  • 2012-12-11
  • 2013-02-19
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
  • 2022-10-04
  • 2017-11-19
  • 1970-01-01
相关资源
最近更新 更多