88from django .contrib .auth .decorators import (login_required , user_passes_test )
99from django .contrib .admin .utils import (quote , unquote )
1010from django .utils .decorators import method_decorator
11+ from django .utils .functional import SimpleLazyObject
1112
1213from log_viewer import settings
1314from log_viewer .utils import (readlines_reverse , JSONResponseMixin )
@@ -20,8 +21,10 @@ class LogJsonView(JSONResponseMixin, TemplateView):
2021 def dispatch (self , * args , ** kwargs ):
2122 return super (LogJsonView , self ).dispatch (* args , ** kwargs )
2223
23- def get_log_json (self , file_name = None , page = 1 ):
24+ def get_log_json (self , original_context = {} ):
2425 context = {}
26+ page = original_context .get ('page' , 1 )
27+ file_name = original_context .get ('file_name' )
2528
2629 # Clean the `file_name` to avoid relative paths.
2730 file_name = unquote (file_name ).replace ('/..' , '' ).replace ('..' , '' )
@@ -88,8 +91,13 @@ def get_log_json(self, file_name=None, page=1):
8891 return context
8992
9093 def render_to_response (self , context , ** response_kwargs ):
91- log_json = self .get_log_json (context .get ('file_name' ),
92- context .get ('page' , 1 ))
94+
95+ # to support Djang 3.1.* (fixed issue #6)
96+ file_name = context .get ('file_name' )
97+ if isinstance (file_name , SimpleLazyObject ):
98+ context = context ['view' ].kwargs
99+
100+ log_json = self .get_log_json (context )
93101
94102 if 'file' in log_json :
95103 log_json ['file' ] = log_json ['file' ].name
0 commit comments