Problems passing variables to templates (utemplates/micropython) ESP32 #328
Unanswered
rubenelias
asked this question in
Q&A
Replies: 2 comments 1 reply
-
|
Yes, this is because you are writing your template using the Jinja syntax, but uTemplate works differently, in particular it requires arguments to be declared explicitly. See the uTemplate readme for more details. There are also some example templates in this repository. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Based on Miguel comments, i solve the problem adding a new line at the beginning of the html template. In this case, I added
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have a couple of days working with this great library. However, whenever I try to pass a variable to the render method of Template class I get a NameError. I don't really know what can be happening since everything looks ok.
Traceback (most recent call last):
File "/lib/microdot/microdot.py", line 1434, in dispatch_request
File "/lib/microdot/microdot.py", line 45, in invoke_handler
File "main.py", line 51, in index
File "/lib/microdot/utemplate.py", line 44, in render
File "templates/smartbell_html.py", line 125, in render
NameError: name 'colegio' isn't defined
Micropython code:
`
from microdot import Microdot, send_file
from microdot.utemplate import Template
app = Microdot()
@app.route('/')
async def index(request):
colegio = 'Kalil Gibran'
return Template('smartbell.html').render(colegio=colegio), {'Content-Type': 'text/html'}
HTML Code:
`
Beta Was this translation helpful? Give feedback.
All reactions