Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_block breaks django permission with htmx rendered template? #50

Open
gmaz-tauruz opened this issue Apr 1, 2024 · 6 comments
Open

Comments

@gmaz-tauruz
Copy link

In the rendered template via htmx ajax call, { % perms.foo.change_bar %} will not work, and {{ perms }} returns empty?

@gmaz-tauruz
Copy link
Author

This happens only when using render_block_to_string(), otherwise ok if i use TemplateResponse()

@clokep
Copy link
Owner

clokep commented Apr 15, 2024

Can you provide a more complete example of the issue you're running into? What is perms? What are the results from render_block_to_string vs TemplateResponse?

@gmaz-tauruz
Copy link
Author

gmaz-tauruz commented Apr 16, 2024 via email

@clokep
Copy link
Owner

clokep commented Apr 16, 2024

If you have a reference to the article that would be helpful too. In general handling any sort of business logic in templates is usually a bad idea though.

@gmaz-tauruz
Copy link
Author

gmaz-tauruz commented Apr 17, 2024 via email

@dwasyl
Copy link

dwasyl commented Sep 21, 2024

I'm thinking this issue is happening because render_block_to_string doesn't load the context_processors which is where perms (or user) comes from. It's possible to add it to the context yourself when using render_block_to_string, it's just a bit clunky. I'm not sure if this is the actual problem though, or if there's an easy fix vs this is an architectural decision?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants