Skip to content

Commit 9ea83ff

Browse files
committed
Merge remote-tracking branch 'origin/template-permissions-gotcha' into release-1.1.0-rc1
2 parents 888c441 + b736931 commit 9ea83ff

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ If you're using REST framework generic views, you can also add a view mixin, `ze
137137

138138
If you absolutely definitely can't avoid running a query in a part of your codebase that's being executed under a `queries_disabled` block, there is another context manager called `queries_dangerously_enabled` which allows you to temporarily re-enable database queries.
139139

140+
### Permissions gotcha
141+
142+
Accessing permissions in your templates (via the `{{ perms }}` template variable) can be a source of queries at template-render time. Fortunately, Django's permission checks are [cached by the `ModelBackend`](https://docs.djangoproject.com/en/2.2/topics/auth/default/#permission-caching), which can be pre-populated by calling `request.user.get_all_permissions()` in the view, before rendering the template.
143+
140144
### How does it work?
141145

142146
Probably best not to ask.
@@ -150,4 +154,3 @@ Install from PyPI
150154
## Code of conduct
151155

152156
For guidelines regarding the code of conduct when contributing to this repository please review [https://www.dabapps.com/open-source/code-of-conduct/](https://www.dabapps.com/open-source/code-of-conduct/)
153-

0 commit comments

Comments
 (0)