Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

redirects.py 1.1KB

1234567891011121314151617181920212223242526272829
  1. from __future__ import absolute_import, unicode_literals
  2. from django.template.response import SimpleTemplateResponse
  3. from django.utils.translation import ugettext_lazy as _
  4. from debug_toolbar.panels import Panel
  5. class RedirectsPanel(Panel):
  6. """
  7. Panel that intercepts redirects and displays a page with debug info.
  8. """
  9. has_content = False
  10. nav_title = _("Intercept redirects")
  11. def process_response(self, request, response):
  12. if 300 <= int(response.status_code) < 400:
  13. redirect_to = response.get('Location', None)
  14. if redirect_to:
  15. status_line = '%s %s' % (response.status_code, response.reason_phrase)
  16. cookies = response.cookies
  17. context = {'redirect_to': redirect_to, 'status_line': status_line}
  18. # Using SimpleTemplateResponse avoids running global context processors.
  19. response = SimpleTemplateResponse('debug_toolbar/redirect.html', context)
  20. response.cookies = cookies
  21. response.render()
  22. return response