Package: django-bootstrap-pagination-nigelm
Django Bootstrap PaginationCurrent VersionVersion:2.0.1Original PackageThis package was originally found athttps://github.com/jmcclell/django-bootstrap-paginationThis version has had some modifications to work with later versions of Django,
and some additional functionality is being grafted in. This is still a work in
progress.Bootstrap CompatibilityVersionsBootstrapNotes< 2.0.0See original>= 2.0.03.x, 4.x, 5.xWorks effectively with versions over this rangeThis application serves to make using Twitter's Bootstrap Pagination styles work
seamlessly with Django Page objects. By passing in a Page object and one or more
optional arguments, Bootstrap pagination bars and pagers can be rendered with
very little effort.Compatible with Django 3.x and 4.x and with Bootstrap versions from 3.x through
5.xInstallationPIPThis will install the latest stable release from PyPi.pipinstalldjango-bootstrap-pagination-nigelmDownloadDownload the latest stable distribution from:http://pypi.python.org/pypi/django-bootstrap-pagination-nigelmDownload the latest development version from:github @https://github.com/nigelm/django-bootstrap-pagination-nigelmUsageSetupMake sure you include bootstrap_pagination in your installed_apps list in
settings.py:INSTALLED_APPS=('bootstrap_pagination',)Additionally, include the following snippet at the top of any template that
makes use of the pagination tags:{%loadbootstrap_pagination%}Finally, make sure that you have the request context processor enabled:TEMPLATES=[{# ...'OPTIONS':{context_processors': [# ...'django.template.context_processors.request',]}}]bootstrap_paginateAll Optional Arguments:-range- Defines the maximum number of page links to show. Ignored in elided
mode.elided- Boolean value - if true then the page is in elided mode, where the
first and last sets of pages, and a group of pages around the current page are
shown, with an ellipsis entry wherever a set of pages are skipped.on_each_side- number of pages shown before/after the current page in elided
mode. Default value 3.on_ends- number of pages shown at the start/finish of the set of pages in
elided mode. Default value 2.show_prev_next- Boolean. Defines whether or not to show the Previous and
Next links. (Accepts"true"or"false")previous_label- The label to use for the Previous linknext_label- The label to use for the Next linkellipsis_label- The text to display for skipped page sets. Defaults to&hellip;show_first_last- Boolean. Defines whether or not to show the First and Last
links. (Accepts"true"or"false")first_label- The label to use for the First page linklast_label- The label to use for the Last page linkshow_index_range- Boolean, defaults to "false". If "true" shows index range
of items instead of page numbers in the paginator. For example, if paginator
is configured for 50 items per page, show_index_range="true" will display
[1-50, 51-100,101-150, 151-200, 201-250, etc.] rather than [1, 2,3,
4, 5, etc.].url_view_name- A named URL reference (such as one that might get passed
into the URL template tag) to use as the URL template. Must be resolvable by
thereverse()function.If this option is not specified, the tag simply
uses a relative url such as?page=1which is fine in most situationsurl_param_name- Determines the name of theGETparameter for the page
number. The default is"page". If nourl_view_nameis defined, this
string is appended to the url as?{{url_param_name}}=1.url_extra_args-Only valid when url_view_name is set.Additional
arguments to pass intoreverse()to resolve the URL.url_extra_kwargs-Only valid whenurl_view_nameis set.Additional
named arguments to pass intoreverse()to resolve the URL. Additionally, the
template tag will add an extra parameter to this for the page, as it is
assumed that if given a url_name, the page will be a named variable in the URL
regular expression. In this case, theurl_param_namecontinues to be the
string used to represent the name. That is, by default,url_param_nameis
equal topageand thus it is expected that there is a namedpageargument
in the URL referenced byurl_view_name. This allows us to use pretty
pagination URLs such as/page/1extra_pagination_classes- A space separated list of CSS class names that
will be added to the top level<ul>HTML element. In particular, this can be
utilized in Bootstrap 4 installations to add the appropriate alignment classes
from Flexbox utilities: eg:justify-content-centerhx_target- For use with HTMX pages, sets the target id, it will also change
all the links to usehx-getinstead ofhrefand adds ahx-swap="OuterHTML"Basic UsageThe following will show a pagination bar with a link to every page, a previous
link, and a next link:{%bootstrap_paginatepage_obj%}The following will show a pagination bar with at most 10 page links, a previous
link, and a next link:{%bootstrap_paginatepage_objrange=10%}The following will show a pagination bar with at most 10 page links, a first
page link, and a last page link:{%bootstrap_paginatepage_objrange=10show_prev_next="false"show_first_last="true"%}Advanced UsageGiven a url configured such as:archive_index_view=ArchiveIndexView.as_view(date_field='date',paginate_by=10,allow_empty=True,queryset=MyModel.all(),template_name='example/archive.html')urlpatterns=patterns('example.views',url(r'^$',archive_index_view,name='archive_index'),url(r'^page/(?P<page>\d+)/$',archive_index_view,name='archive_index_paginated'))We could simply use the basic usage (appending ?page=#) with thearchive_indexURL above, as thearchive_index_viewclass based generic view from django
doesn't care how it gets the page parameter. However, if we want pretty URLs,
such as those defined in thearchive_index_paginatedURL (ie: /page/1), we
need to define the URL in our template tag:{%bootstrap_paginatepage_objurl_view_name="archive_index_paginated"%}Because we are using a default page parameter name of "page" and our URL
requires no other parameters, everything works as expected. If our URL required
additional parameters, we would pass them in using the optional argumentsurl_extra_argsandurl_extra_kwargs. Likewise, if our page parameter had
a different name, we would pass in a differenturl_param_nameargument to
the template tag.bootstrap_pagerA much simpler implementation of the Bootstrap Pagination functionality is the
Pager, which simply provides a Previous and Next link.All Optional Arguments:-previous_label- Defines the label for the Previous linknext_label- Defines the label for the Next linkprevious_title- Defines the link title for the previous linknext_title- Defines the link title for the next linkcentered- Boolean. Defines whether or not the links are centered. Defaults
to false. (Accepts "true" or "false")url_view_name- A named URL reference (such as one that might get passed
into the URL template tag) to use as the URL template. Must be resolvable by
thereverse()function.If this option is not specified, the tag simply
uses a relative url such as?page=1which is fine in most situationsurl_param_name- Determines the name of theGETparameter for the page
number. Th default is"page". If nourl_view_nameis defined, this string
is appended to the url as?{{url_param_name}}=1.url_extra_args-Only valid whenurl_view_nameis set.Additional
arguments to pass intoreverse()to resolve the URL.url_extra_kwargs-Only valid whenurl_view_nameis set.Additional
named arguments to pass intoreverse()to resolve the URL. Additionally, the
template tag will add an extra parameter to this for the page, as it is
assumed that if given a url_name, the page will be a named variable in the URL
regular expression. In this case, theurl_param_namecontinues to be the
string used to represent the name. That is, by default,url_param_nameis
equal to"page"and thus it is expected that there is a namedpageargument in the URL referenced byurl_view_name. This allows us to use
pretty pagination URLs such as/page/1url_anchor- The anchor to use in URLs. Defaults toNoneextra_pager_classes- A space separated list of CSS class names that will be
added to the top level<ul>HTML element. This could be used to, as an
example, add a class to prevent the pager from showing up when printing.Normal UsageUsage is basically the same as for bootstrap_paginate. The simplest usage is:{%bootstrap_pagerpage_obj%}A somewhat more advanced usage might look like:{%bootstrap_pagerpage_objprevious_label="Newer Posts"next_label="Older Posts"url_view_name="post_archive_paginated"%}