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

Forward Context instance #21

Merged
merged 6 commits into from
Oct 2, 2020
Merged

Conversation

bblanchon
Copy link
Contributor

This pull request makes render_block_to_string() forwards the Context instance provided by the user.

For example, this allows the user to disable autoescape, like so:

result = render_block_to_string(template, block, Context(context, autoescape=False))

Such a feature is handy when rendering a text-only template, like an email or a notification message.

@clokep clokep self-requested a review September 30, 2020 16:46
@clokep
Copy link
Owner

clokep commented Sep 30, 2020

Seems pretty reasonable. Thanks for including tests!

Any idea if there are changes that should be made to the Jinja code in this situation?

@bblanchon
Copy link
Contributor Author

No, I don't know if there is something similar for Jinja, but since Context is in the django.template namespace, the user knows it's a feature limited to Django templates.

BTW, django-templated-email expects this behavior; they've been waiting for a fix since 2017 😮.

@clokep
Copy link
Owner

clokep commented Oct 2, 2020

No, I don't know if there is something similar for Jinja, but since Context is in the django.template namespace, the user knows it's a feature limited to Django templates.

Right so theoretically you could create a django.template.Context instance and pass it into render_block_to_string which could call into the Jinja2 code. That's just silly (although I actually think Jinja2 would convert it to a dict, which probably works). Anyway, I don't think we need to do anything about it.

tests/tests.py Outdated Show resolved Hide resolved
@clokep clokep merged commit 6f243f0 into clokep:main Oct 2, 2020
@bblanchon bblanchon deleted the forward-context-instance branch October 3, 2020 06:34
@clokep
Copy link
Owner

clokep commented Oct 6, 2020

FYI I released 0.8 with this change in it. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants