-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
[Feature Request] Render template from string #72
Comments
I will add a PR for this |
Looking at this... I think all that's necessary is returning the from sanic import html
TEMPLATE = '''
<html>
<body>
...
</body>
</html>'''
rendered = render_from_string(TEMPLATE, context)
return html(rendered) |
@prryplatypus Not sure I follow. We don't have a Once we'll have this function, I'm not sure why we need to use the |
@azimovMichael You are correct, we do not have that function yet. Your strategy is fine. The question that I have is does it make sense to have Why not something like this: def render(template_name="", template="", ...):
if template_name and template:
raise SomeException
render("my_template_name") # backwards compat, keep this as first arg
render(template="<html>...") |
@ahopkins I wanted to provide a similar API to what Flask and Jinja itself provide, but sure we can do it in a single function. |
That makes sense. I personally don't like polluting the namespace so much 🤷♂️. I don't work on jinja much so this is helpful for me to know. What if we provide both? I'd even go so far as to make it a keyword only argument on |
I'm actually totally fine with providing all in a single function. |
Is your feature request related to a problem? Please describe your use case.
I'm migrating from Flask to Sanic, and currently I'm using Flask's render_template_string to render a jinja template from a string.
If I understand correctly, Sanic only supports rendering from a file.
Describe the solution you'd like
I would like something like this:
The text was updated successfully, but these errors were encountered: