Massimo Di Pierro <massimo....@gmail.com>: Jan 31 08:55PM -0800
I committed some new code to py4web
Now you can do:
from . common import authenticated, unauthenticated # from latest _scaffold
# exposes index as /{app_name}/index and uses index.html or generic.html
template, auth.user, db, T, session
@authenticated()
def index():
return dict()
# GET only
@authenticated.get()
def index():
return dict()
# exposes /{app_name}/index/<a>/<b>/<c>
@authenticated.get()
def index(a,b,c):
return dict()
# more explicit
@authenticated.get("index/<a:int>/<b:int>/<c:re:.*>)
def index(a,b,c):
return dict()
Some magic
# define a button that make the following serverside POST callback
@unauthenticated.button("click me")
def a_button(msg):
print("you clicked the button and server received:", msg)
# expose a page that displays the button which - onclick - makes the
ballback
@unauthenticated.get()
def show_a_button():
return dict(mybutton = a_button(msg="hello world"))
Thoughts? Should we keep this API? Can we improve it?
|