def process_response(self, request, response):
if not request.is_ajax() and not isinstance(response, HttpResponseRedirect) and hasattr(response, 'content'):
content = force_text(response.content, encoding=response.charset)
if '</body>' not in content:
return response
json_cfg = {}
if hasattr(response, 'context_data'):
json_cfg = response.context_data.get('json_cfg', {})
template = get_template('ajaxviews/_middleware.html')
html = template.render({
'json_cfg': json_cfg,
'main_name': settings.REQUIRE_MAIN_NAME,
})
l_content, r_content = content.rsplit('</body>', 1)
content = ''.join([l_content, html, '</body>', r_content])
response.content = response.make_bytes(content)
if response.get('Content-Length', None):
response['Content-Length'] = len(response.content)
return response
评论列表
文章目录