|
||||||||
|
||||||||
Last edition : 2009/03/28 14:29
AEWebAEWeb is not another python web framework ! It's just a wrapper around webapp, providing some facilities. It was designed to work on Google App Engine, but it works outside, if you provide webapp and webob. In the past, I used the marvelous webpy on GAE accounts. But webpy is going to be too big for my needs (bloatware ? it's not what I said). In fact, webapp is already pretty good, and it's based on the fabulous webob for its request and response objects. So everything I needed was here, and I had just make a lite wrapper (for syntaxic sugar). Here is the simplest "hello world" :
Note that restful methods are uppercase (like webpy), and they can act as generators too. In this case, return "Hello World" could be possible too. In fact, all what is returned or yielded is sent in the response body (like webpy). Another thing I've stollen from webpy is the autodelegate concept :
Now, this app will reply on path '/' and '/hello'. Others will receive a 404 Not Found. Note that '/' go to GET_index (index is used when path is empty). But the delegate method can do more : it can use input parameters (query and post parameters) as method arguments like this :
So, this app will display "hello world" for url "/", and "hello marc" for url "/?name=marc". Note that it will send back a 404 Not Found for "/?nom=marc" ! In fact, when it doesn't found the right "get method", it will call self.notfound(), which will send back the 404 http status, and the content of Web.page_notfound(). So, you should call self.notfound() if you want to send back a 404 Not Found on your own. If you want to redefine this content, simply do that, before calling the run process:
Note that w is your Web instance. (Web.page_notfound() can receive one parameter) The run process (aka Web.run() ), is in fact, a shortcut to run only one app. This call :
is the same as :
In fact : Web.app() return a WSGI app, which contains 2 methods : ... in progress ...Web staticmethod api :Web.app( routes, middlewares=None, debug=False ) : return a "wsgi app" with 2 new methods Web.run( routes, middlewares=None, debug=False ) : shortcut method to Web.app().run() ... in progress ...Web Instance api :self.delegate( prefix, page, inputAsArgs=False ) self.is_dev self.set_cookie() self.del_cookie() self.cookies self.environ self.url self.path self.header( name, value ) self.has_key( name ) self[ name ] ... in progress ...Get aeweb.pyDownload latest version |
||||||||
|