Help Needed With utemplate

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Help Needed With utemplate

Post by bitninja » Tue Nov 28, 2017 1:38 am

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
result.jpg (14.03 KiB) Viewed 5115 times
Am I doing anything wrong?

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Help Needed With utemplate

Post by SpotlightKid » Thu Nov 30, 2017 1:39 am

What are you passing as the first argument (i.e. for the param 'pkg') when creating your WebApp instance?

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: Help Needed With utemplate

Post by bitninja » Thu Nov 30, 2017 2:58 am

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

Code: Select all

app = picoweb.WebApp(__name__)

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Help Needed With utemplate

Post by SpotlightKid » Thu Nov 30, 2017 8:28 am

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

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: Help Needed With utemplate

Post by bitninja » Thu Nov 30, 2017 10:39 pm

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?

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Help Needed With utemplate

Post by pfalcon » Fri Dec 01, 2017 1:33 pm

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.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: Help Needed With utemplate

Post by bitninja » Sun Dec 03, 2017 12:37 am

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.

Post Reply