Return context variables helpful for debugging.
(request)
| 36 | |
| 37 | |
| 38 | def debug(request): |
| 39 | """ |
| 40 | Return context variables helpful for debugging. |
| 41 | """ |
| 42 | context_extras = {} |
| 43 | if settings.DEBUG and request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS: |
| 44 | context_extras["debug"] = True |
| 45 | from django.db import connections |
| 46 | |
| 47 | # Return a lazy reference that computes connection.queries on access, |
| 48 | # to ensure it contains queries triggered after this function runs. |
| 49 | context_extras["sql_queries"] = lazy( |
| 50 | lambda: list( |
| 51 | itertools.chain.from_iterable( |
| 52 | connections[x].queries for x in connections |
| 53 | ) |
| 54 | ), |
| 55 | list, |
| 56 | ) |
| 57 | return context_extras |
| 58 | |
| 59 | |
| 60 | def i18n(request): |