在Django-pagination中,Paginate不起作用

时间:2010-06-17 07:08:51

标签: django paginate django-pagination

问题:如何正确强制分页?问题是{% paginate %}不起作用,但其他{% load pagination_tags %}{% autopaginate object_list 10 %}有效!

当我将{% paginate %}添加到html页面时出现错误消息:

TemplateSyntaxError at /logging
Caught an exception while rendering: pagination/pagination.html

我做了什么:

  1. 安装django-pagination没有任何问题。当我在python import pagination中进行操作时,它运行良好。

  2. 在settings.py中添加了对INSTALLED_APP的分页:

    INSTALLED_APPS =(     #...,     “分页”, )

  3. 在settings.py中添加:

    TEMPLATE_CONTEXT_PROCESSORS =(     “django.core.context_processors.auth”     “django.core.context_processors.debug”     “django.core.context_processors.i18n”     “django.core.context_processors.media”     “django.core.context_processors.request” )

  4. 还要添加到settings.py中间件:

    MIDDLEWARE_CLASSES =(            #...            'pagination.middleware.PaginationMiddleware',        )

  5. 在views.py中添加到顶部:

    来自django.template import RequestContext

  6. 最后添加到我的HTML模板页面行:

    {%load pagination_tags%} ... {%autopaginate item_list 50%} {%for item_list%}中的商品 ... {%endfor%} {%paginate%}

  7. 感谢。


    已添加:错误报告顶部:

    TemplateSyntaxError at /logging
    Caught an exception while rendering: pagination/pagination.htmlRequest Method:  GET
    Request URL:    http://host:8123/logging?portfolio_id=1
    Exception Type: TemplateSyntaxError
    Exception Value:    Caught an exception while rendering: pagination/pagination.html
    Exception Location: /usr/local/lib/python2.6/dist-packages/django/template/debug.py in render_node, line 81
    Python Executable:  /usr/bin/python
    Python Version: 2.6.2
    Python Path:    ['/home/mosg/sources/django/apm', '/usr/local/lib/python2.6/dist-packages/django_pagination-1.0.5-py2.6.egg', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/var/lib/python-support/python2.6', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages']
    Server time:    Thu, 17 Jun 2010 06:29:45 -0500
    
    Template error
    
    In template /home/mosg/sources/django/apm/templates/accounting/logging.html, error at line 93
    Caught an exception while rendering: pagination/pagination.html
    83      <td>{{ item.transaction_datetime }}</td>
    84      <td>{{ item.src_account }}</td>
    85      <td>{{ item.dst_account }}</td>
    86      <td>{{ item.body }}</td>
    87      <td>{{ item.estimated }}</td>
    88  <!--
    89      <td><a href="./admin/accounting/transaction/{{item.id}}/">edit</a></td>
    90  -->
    91  </tr>
    92  {% endfor %}
    93  {% paginate %}
    94  </table>
    95  {% else %}
    96      <p>No transaction logs are available.</p>
    97  {% endif %}
    98          </div>
    99      
    100 
    101 </div>
    102        
    103         <br class="clear" />
    

    stevejalim

    已添加

    @login_required
    def logging(request):
        pid = request.GET.get('portfolio_id', 1)
        item_list = TransactionsLogging.objects.filter(Q(portfolio_id=pid)).order_by('-datetime')
        return render_to_response('accounting/logging.html', {'item_list': item_list, 'user': request.user,}, context_instance = RequestContext(request))
    

    PS:需要进行一些编辑,因为我不能在这里很好地使用代码样式:)

2 个答案:

答案 0 :(得分:1)

你能提供关于TemplateSyntaxError的更多细节吗?

所有配置看起来都很好。 在pagination/pagination.html模板中有{% load i18n %}。您的设置文件中有USE_I18N = True吗?

答案 1 :(得分:0)

之前发现了解决方案:django-pagination您需要使用最新版本,这可以修复错误!