Fixes for Django up to 2.2
[django-pagination.git] / fnp_django_pagination / templatetags / pagination_tags.py
index c56f44d..3802a47 100644 (file)
@@ -43,9 +43,14 @@ from django.template import (
 )
 
 try:
-    from django.template.base import TOKEN_BLOCK
-except ImportError:     # Django < 1.8
-    from django.template import TOKEN_BLOCK
+    from django.template.base import TokenType
+    TOKEN_BLOCK = TokenType.BLOCK
+except ImportError:
+    try:
+        # Django 1.8-1.11
+        from django.template.base import TOKEN_BLOCK
+    except ImportError:     # Django < 1.8
+        from django.template import TOKEN_BLOCK
 
 from django.template.loader import select_template
 from django.utils.text import unescape_string_literal
@@ -195,8 +200,7 @@ class PaginateNode(Node):
         new_context = paginate(context)
         if self.template:
             template_list.insert(0, self.template)
-        with context.push(new_context):
-            return loader.render_to_string(template_list, context)
+        return loader.render_to_string(template_list, new_context)
 
 
 def do_paginate(parser, token):