Page 1 of 1
Help Needed With utemplate
Posted: Tue Nov 28, 2017 1:38 am
by bitninja
I wanted to try using the utemplate library with PicoWeb, but am having some type of issue running the example apps when they render the 'squares.tpl' file.
Code: Select all
32.000 <HTTPRequest object at 3fff3e30> <StreamWriter <socket state=2 timeout=0 incoming=0 off=0>> AttributeError("'module' object has no attribute '__path__'",)
Traceback (most recent call last):
File "picoweb/__init__.py", line 197, in _handle
File "example_webapp2.py", line 17, in squares
File "picoweb/__init__.py", line 240, in render_template
File "picoweb/__init__.py", line 236, in _load_template
File "utemplate/source.py", line 153, in __init__
AttributeError: 'module' object has no attribute '__path__'
I think it may be related to how I installed utemplate as a frozen module. This is part of my 'modules' directory in the ESP8266 port.

- result.jpg (14.03 KiB) Viewed 6289 times
Am I doing anything wrong?
Re: Help Needed With utemplate
Posted: Thu Nov 30, 2017 1:39 am
by SpotlightKid
What are you passing as the first argument (i.e. for the param 'pkg') when creating your WebApp instance?
Re: Help Needed With utemplate
Posted: Thu Nov 30, 2017 2:58 am
by bitninja
It's the example_webapp.py and example_webapp2.py files from the PicoWeb repository...
Code: Select all
app = picoweb.WebApp(__name__, ROUTES)
app.run(debug=True)
and
Re: Help Needed With utemplate
Posted: Thu Nov 30, 2017 8:28 am
by SpotlightKid
I don't think the way utemplate tries to locate the template modules works with frozen modules.
You might want to open an issue here:
https://github.com/pfalcon/utemplate/issues
Re: Help Needed With utemplate
Posted: Thu Nov 30, 2017 10:39 pm
by bitninja
Thanks for the recommendation.
I will try using utemplate without freezing it into the firmware. The last time I tried this though I seemed to have an out-of-memory issues.
I guess what bothers me now is that there are no clear steps for installing (into the ESP8266 firmware) PicoWeb and it's dependencies uasyncio and utemplate. Maybe I am missing something?
Re: Help Needed With utemplate
Posted: Fri Dec 01, 2017 1:33 pm
by pfalcon
Maybe I am missing something?
You did. Even though you read
viewtopic.php?f=16&t=2966&p=20150 (last message is yours), you apparently missed
viewtopic.php?f=16&t=2966&p=20150&hilit ... ico#p20150 which shows the best practices on how to deploy a full-stack web application (templates, database, etc.) on a baremetal target like ESP8266.
The rest of the suggestions are also not new, and were sounded on forum many times:
- If you work with MicroPython, you work with "unix" version on your "desktop" machine. If you do it otherwise, you do it hard on yourself. If you don't have a Linux box to run "unix" version, you still have it, in a virtual machine on whatever OS you run.
- With unix version, most stuff "just works" (or you're doing something wrong; or you hit a bug).
- When you made it work on unix port, you move to baremetal port. Then it either just works (because you already got an experience with it), or if something goes wrong, you at least can compare with how it works on unix port, and understand where the problem lies and how to fix it.
- Sometimes, the above workflow doesn't work (e.g. when dealing with hardware). You still do as much as possible on unix version, mocking hardware stuff, and move to baremetal only when the core logic works as expected.
Hope that helps.
Re: Help Needed With utemplate
Posted: Sun Dec 03, 2017 12:37 am
by bitninja
pfalcon wrote: ↑Fri Dec 01, 2017 1:33 pm
Hope that helps.
Thanks! Yes, I had tested Pico-Notes before but missed the points about testing in the unix port first and
then deploying to the board. It seemed rather natural to me to just have PicoWeb/uasyncio frozen and then have my app and pages on the flash file space. Everything works as I expect (except templates) and I don't find it that painful at all. I'll admit though, my requirements are minimal... I just need enough of a web application to change a value or return a status. Maybe just serve a little content.
I'm actually having alot of success with another example you wrote
here...
I really appreciate all the time and effort you have put into everything. It's good work.