Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if it has not been provided by either a view decorator or the middleware
(request)
| 17 | |
| 18 | |
| 19 | def csrf(request): |
| 20 | """ |
| 21 | Context processor that provides a CSRF token, or the string 'NOTPROVIDED' |
| 22 | if it has not been provided by either a view decorator or the middleware |
| 23 | """ |
| 24 | |
| 25 | def _get_val(): |
| 26 | token = get_token(request) |
| 27 | if token is None: |
| 28 | # In order to be able to provide debugging info in the |
| 29 | # case of misconfiguration, we use a sentinel value |
| 30 | # instead of returning an empty dict. |
| 31 | return "NOTPROVIDED" |
| 32 | else: |
| 33 | return token |
| 34 | |
| 35 | return {"csrf_token": SimpleLazyObject(_get_val)} |
| 36 | |
| 37 | |
| 38 | def debug(request): |