我在设置 django-pagination 时遇到问题
我正在为 Django 网站制作一个模板(它是报价数据库)。我想要像 Digg 一样的分页。尽管如此,该应用程序的作者已经制作了自己的分页,不幸的是没有页面编号(只是“上一个”和“下一个”链接)。所以我已经安装了 django-pagination,但我无法在该网站上使用它。我对 Django 完全陌生,甚至编程 - 我只是一个简单的网页设计师......好吧,我们开始吧。
有原始脚本: https://bitbucket.org/fleg/fqdb/
第一件事是模板上下文处理器的问题。我的 settings.py 没有这个部分,所以我添加它就像在 django-pagination 文档中一样。当我运行该网站时,出现错误:“将 'django.contrib.auth.context_processors.auth' 放入 TEMPLATE_CONTEXT_PROCESSORS 设置中以便使用管理应用程序”。那么我该如何订购呢?
第二个问题是模板。我使用它完全就像截屏视频:
{% extends "fqdb/base.html" %}
{% load pagination_tags %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
{% if quotes %}
{% autopaginate quotes %}
{% for quote in quotes %}
{% include 'fqdb/quote_body.html' %}
{% endfor %}
{% paginate %}
{% else %}
<p>Brak cytatów.</p>
{% endif %}
{% endblock %}
但我收到“模板错误:渲染时捕获 KeyError:请求”。但是...说真的,我不知道这段代码有什么问题!
有分页视图 - 报价列表。它无需分页即可工作,所以我认为这不是问题,但也许是。
def list_paged(request, page, order_by_what, title, reverse_name):
hash = get_ip_hash(request)
lista = Quote.objects.filter(accepted = True).order_by(order_by_what)[:]
returnDict = {'quotes': lista, 'title': title, 'hash': hash, 'sidebar': get_sidebar()}
return render_to_response('fqdb/quote_list.html', {'quotes': get_quotes(quotes)}, context_instance=RequestContext(request))
我已将其修改为不分页,因为它是 django 分页任务。您可以在 Bitbucket 上找到原始视图。
也许您知道一些更好的分页解决方案?
I'm making a template for Django site (it's quote database). I wanna have Digg-like pagination. Altough, author of the application has made his own pagination, unfortunately without page numering (just "previous" and "next" links). So I've installed django-pagination, but I can't use it with the site. I'm completly new in Django, even programming - I'm just a simple webdesigner... OK, here we go.
There is the original script: https://bitbucket.org/fleg/fqdb/
The first thing is a problem with template context processors. My settings.py didn't have this section, so I added it exactly like in django-pagination documentation. When I run the site, I get an error: "Put 'django.contrib.auth.context_processors.auth' in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application". So how I have to order that?
A second problem is template. I use it exactly like on the screencast:
{% extends "fqdb/base.html" %}
{% load pagination_tags %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
{% if quotes %}
{% autopaginate quotes %}
{% for quote in quotes %}
{% include 'fqdb/quote_body.html' %}
{% endfor %}
{% paginate %}
{% else %}
<p>Brak cytatów.</p>
{% endif %}
{% endblock %}
But I get "Template error: Caught KeyError while rendering: request". But... Seriously, I don't know what's wrong with this code!
There is the paginated view - quote list. It work without pagination, so I don't think if it's a problem, but maybe.
def list_paged(request, page, order_by_what, title, reverse_name):
hash = get_ip_hash(request)
lista = Quote.objects.filter(accepted = True).order_by(order_by_what)[:]
returnDict = {'quotes': lista, 'title': title, 'hash': hash, 'sidebar': get_sidebar()}
return render_to_response('fqdb/quote_list.html', {'quotes': get_quotes(quotes)}, context_instance=RequestContext(request))
I have modified it to not paginating, because it's django-pagination task. You can find original view on Bitbucket.
Maybe do you know some better pagination solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您需要添加
django.contrib.auth.context_processors.auth
和django.core.context_processors.request
上下文处理器到您的TEMPLATE_CONTEXT_PROCESSORS
设置。在定义 TEMPLATE_CONTEXT_PROCESSORS 之前,django 将使用默认值。看起来您的某些代码似乎需要
auth
处理器,因此您出现了第一条错误消息。在我看来,
KeyError
就好像您需要request
处理器一样。在您的设置文件中尝试以下操作:
我使用了 Django 1.3 请求上下文文档,添加了请求处理器,并注释掉了您似乎不需要的那些。
模板上下文处理器的顺序通常并不重要,只要它们不定义重叠的变量名称即可。
It looks like you need to add
django.contrib.auth.context_processors.auth
anddjango.core.context_processors.request
context processors to yourTEMPLATE_CONTEXT_PROCESSORS
setting.Before you defined
TEMPLATE_CONTEXT_PROCESSORS
, django would have used the default. It looks as if some of your code requires theauth
processor, hence your first error message.The
KeyError
looks to me as if you require therequest
processor.Try the following in your settings file:
I've used the default list given in the Django 1.3 request context docs, added the request processor, and commented out the ones that you don't seem to need.
The order of template context processors does not usually matter, as long as they do not define overlapping variable names.
如果对象是从模板标签传递的,
请注意:'request': context['request']
If the objects are passed from a templatetag
note the: 'request': context['request']
N
- 每页需要多少个项目N
- how many items you need for each page