1. Installationlinaro
-
django
-
pagination
Settings
Installed_apps = ( # ... 'linaro_django_pagination',) Middleware_classes= ( # ... 'Linaro_django_pagination.middleware.PaginationMiddleware',) Template_context_processors= (#in 1.7 This option is canceled by default, seemingly. How we go about loading in templates and views is an important issue. '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.core.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'django.core.context_processors.request',)
Views
@login_required def documents (Request): Project =d_category.objects.all () Doc =docs.objects.all () return render_to_response ( '
context_instance
=
RequestContext(request)比较重要
These processors will be called in RequestContext order and put some predefined variables into the current context. For example, the ' Django.core.context_processors.auth ' function is to pass variables such as user, messages, perms, etc. to the template by default, describing the current logged on user, the current logged on user's message list, and the currently logged on user's permissions. Finally, when you use the Render_to_response method, RequestContext should be passed in as its third parameter. This is the problem I encountered in 1.7, if you do not use, then wait for the error.
Use in templates
{% load pagination_tags%} {% autopaginate object_list 10%} {% forMessageinchObject_list%} <tr> <td><input type="checkbox" class="Choose"Value="{{message.pk}}"></td> <TDclass="Name {% if Message.is_read%}read{% endif%}"> System Message {%ifMessage.is_read%} (read) {% endif%}</td> <tdclass=" Time">{{message.create_time|date:"y-m-d"}}</td> <td><a href="{{Message.get_absolute_url}}" class="btn Btn_blue"> View </a></td> </tr> {% ENDFOR%} </table> </form> <divclass="NextPage"> <br> <span>{% paginate%}</span> </div>
Django Paging Linaro-django-pagination