Running PicoWeb Examples

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Running PicoWeb Examples

Post by bitninja » Sun Aug 06, 2017 3:13 am

Hello,

I was wondering if someone could help me get the example apps for picoweb running on a Wemos D1 Mini. I am running a flash image with all the frozen modules necessary to run the notes-pico app. The notes app runs but I cannot get this example to completely work...

Code: Select all

#
# This is a picoweb example showing a web page route
# specification using view decorators (Flask style).
#
import picoweb

app = picoweb.WebApp(__name__)

@app.route("/")
def index(req, resp):
    yield from picoweb.start_response(resp)
    yield from resp.awrite("I can show you a table of <a href='squares'>squares</a>.")

@app.route("/squares")
def squares(req, resp):
    yield from picoweb.start_response(resp)
    yield from app.render_template(resp, "squares.tpl", (req,))

@app.route("/test")
def squares(req, resp):
    yield from picoweb.start_response(resp)
    yield from resp.awrite("Link to static content...<a href='/static/sample.html'>sample</a>.")

import logging
logging.basicConfig(level=logging.DEBUG)

app.run(debug=True,host="0.0.0.0")
When I invoke the "/squares" route I get something like this...

Code: Select all

Traceback (most recent call last):
  File "main.py", line 2, in <module>
  File "example2.py", line 28, in <module>
  File "picoweb/__init__.py", line 240, in run
  File "uasyncio/core.py", line 121, in run_forever
  File "uasyncio/core.py", line 85, in run_forever
  File "picoweb/__init__.py", line 156, in _handle
  File "example2.py", line 17, in squares
  File "picoweb/__init__.py", line 194, in render_template
  File "picoweb/__init__.py", line 190, in _load_template
  File "utemplate/source.py", line 153, in __init__
AttributeError: 'module' object has no attribute '__path__'
Thanks.

chrisb2
Posts: 28
Joined: Sat Apr 01, 2017 4:19 am

Re: Running PicoWeb Examples

Post by chrisb2 » Wed Aug 09, 2017 8:55 am

I have exactly the sample problem on an NodeMcu clone esp8266, The base context '/' works fine.

I have squares.tpl in a templates dir, from the top level dir, if I run:

Code: Select all

ldr = utemplate.source.Loader("templates", ".")
ldr.load('squares.tpl')
I get:

Code: Select all

<generator>
which I think indicates it has worked.

chrisb2
Posts: 28
Joined: Sat Apr 01, 2017 4:19 am

Re: Running PicoWeb Examples

Post by chrisb2 » Wed Aug 09, 2017 9:37 am

Fix it!

In example_webapp2.py I made the following change:

Code: Select all

# app = picoweb.WebApp(__name__)
app = picoweb.WebApp(None)
Then when I do at REPL prompt:

Code: Select all

import webapp
and hit /squares I get the correct response.

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

Re: Running PicoWeb Examples

Post by bitninja » Thu Aug 10, 2017 4:56 am

Great! Thanks for the fix.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Running PicoWeb Examples

Post by pythoncoder » Fri Aug 11, 2017 6:44 am

@chrisb2 As it's a demo program it might be worth raising an issue.
Peter Hinch
Index to my micropython libraries.

chrisb2
Posts: 28
Joined: Sat Apr 01, 2017 4:19 am

Re: Running PicoWeb Examples

Post by chrisb2 » Fri Aug 11, 2017 7:40 am


Post Reply