-
-
Notifications
You must be signed in to change notification settings - Fork 252
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] Hope robyn can support returning f-string format #338
Comments
Hey @shaohaiyang . Robyn does support returning f-strings. For example something like this will work
However, you are trying to return an HTML. You can either use templates(https://sansyrox.github.io/robyn/#/features?id=templates) or static_file(https://sansyrox.github.io/robyn/#/examples?id=serving-simple-html-files)) to serve the HTML. |
I hope that helps. Lmk if you need some other information. Or we can close this issue. 😄 |
@sansyrox ,If it can support f """ format, it will works better with jinja2.
|
@shaohaiyang , the traditional |
can you try if this works for you from robyn import Robyn, jsonify
from pathlib import Path
import os
app = Robyn(__file__)
@app.get("/")
def template_render():
context = {"title": "Hello World!", "description": "This is a description"}
return {
"status": "200",
"body": f"""<html>Hellow { context['title'] }</html>""",
"headers": jsonify({"Content-Type": "text/html"}),
}
if __name__ == "__main__":
app.start(port=8000) |
yes,it can works but also need backslash :( |
@shaohaiyang , actually no. This works now :D Without backslash! :D from robyn import Robyn, jsonify
from pathlib import Path
import os
app = Robyn(__file__)
@app.get("/")
def template_render():
context = {"title": "Hello World!", "description": "This is a description"}
return {
"status": "200",
"body": f"""
<html>Hellow { context['title'] }
<p>{ context['description'] }</p>
</html>""",
"headers": {"Content-Type": "text/html"},
}
if __name__ == "__main__":
app.start(port=8000) |
Yes, It works very well when i upgrade robyn to latest verson 0.20.0, thanks again very much . |
Perfect. I am glad it works! :D |
Current Behavior
Could not support return f-string response
for example:
The text was updated successfully, but these errors were encountered: