webapp2 ガイド ( http://webapp-improved.appspot.com/guide/handlers.html )で説明されているように、webapp2 マイクロ フレームワークを使用しています。
import webapp2
class WSGIApplication(webapp2.WSGIApplication):
def __init__(self, *args, **kwargs):
super(WSGIApplication, self).__init__(*args, **kwargs)
self.router.set_dispatcher(self.__class__.custom_dispatcher)
@staticmethod
def custom_dispatcher(router, request, response):
rv = router.default_dispatcher(request, response)
if isinstance(rv, basestring):
rv = webapp2.Response(rv)
elif isinstance(rv, tuple):
rv = webapp2.Response(*rv)
return rv
def route(self, *args, **kwargs):
def wrapper(func):
self.router.add(webapp2.Route(handler=func, *args, **kwargs))
return func
return wrapper
次に、ビュー関数を定義します。
import micro_webapp2
app = micro_webapp2.WSGIApplication()
@app.route('/')
def hello_handler(request, *args, **kwargs):
return 'Hello, world!'
代わりに、テンプレートをレンダリングし、リダイレクトを呼び出し、webapp2 セッション拡張機能を操作したいと考えています。
webapp2 マイクロ フレームワークを使用する場合、どのようにすればよいですか?