开发者

I have problems with setting up django-pagination

开发者 https://www.devze.com 2023-04-12 15:02 出处:网络
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 (j

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?


It looks like you need to add django.contrib.auth.context_processors.auth and django.core.context_processors.request context processors to your TEMPLATE_CONTEXT_PROCESSORS setting.

Before you defined TEMPLATE_CONTEXT_PROCESSORS, django would have used the default. It looks as if some of your code requires the auth processor, hence your first error message.

The KeyError looks to me as if you require the request processor.

Try the following in your settings file:

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    #"django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    #"django.core.context_processors.static",
    #"django.contrib.messages.context_processors.messages")
    "django.core.context_processors.request"
    )

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.


If the objects are passed from a templatetag

def comment_app(context):
    objects = Comments.objects.get_tree_for_object(context['content_object'])
    return {
        'comments_tree': objects,
        'request': context['request']
}
register.inclusion_tag('comments/comment_app.html', takes_context=True)(comment_app)

note the: 'request': context['request']


{% autopaginate quotes N%}

N - how many items you need for each page

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号