Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
WSGIマイクロフレームワーク
WSGI!from wsgiref.simple_server import make_server, demo_apphttpd = make_server(, 8000, demo_app)print "Serving HTTP on po...
WebOb@wsgifydef application(request):  return Response(Hello)http://docs.webob.org
Makoimport osfrom mako.lookup import TemplateLookuphere = os.path.dirname(__file__)templates = TemplateLookup(directories=...
Routesclass Dispatcher(object):   def __init__(self):     self.mapper = Mapper()     self.controllers = {}  def add_route(...
Routes  @wsgify  def __call__(self, request):    matched = self.mapper.routematch(request.path_info,request.method)    if ...
Routesapplication = Dispatcher()application.add_route(index, /, index)application.add_route(hello, /hello, hello)http://ro...
FormEncode Schemaclass HelloSchema(formencode.Schema):   name = validators.UnicodeString(not_empty=True)
FormEncode htmlfilldef hello(request):   try:      params = HelloSchema.to_python(request.params)   except formencode.Inva...
putting all togetherhttps://gist.github.com/1175051
Prochain SlideShare
Chargement dans…5
×

フレームワークなしでWSGIプログラミング

2 828 vues

Publié le

Publié dans : Technologie, Business
  • Soyez le premier à commenter

フレームワークなしでWSGIプログラミング

  1. 1. WSGIマイクロフレームワーク
  2. 2. WSGI!from wsgiref.simple_server import make_server, demo_apphttpd = make_server(, 8000, demo_app)print "Serving HTTP on port 8000..."httpd.serve_forever()
  3. 3. WebOb@wsgifydef application(request): return Response(Hello)http://docs.webob.org
  4. 4. Makoimport osfrom mako.lookup import TemplateLookuphere = os.path.dirname(__file__)templates = TemplateLookup(directories=[os.path.join(here,templates)])tmpl = templates.get_template(index.mak)tmpl.render(request=request)http://www.makotemplates.org/
  5. 5. Routesclass Dispatcher(object): def __init__(self): self.mapper = Mapper() self.controllers = {} def add_route(self, route_name, pattern, controller): self.mapper.connect(route_name, pattern) self.controllers[route_name] = controller
  6. 6. Routes @wsgify def __call__(self, request): matched = self.mapper.routematch(request.path_info,request.method) if not matched: raise HTTPNotFound matchdict, route = matched if route.name not in self.controllers: raise HTTPNotFound request.routes = self.mapper._routenames return self.controllers[route.name](request)
  7. 7. Routesapplication = Dispatcher()application.add_route(index, /, index)application.add_route(hello, /hello, hello)http://routes.groovie.org/
  8. 8. FormEncode Schemaclass HelloSchema(formencode.Schema): name = validators.UnicodeString(not_empty=True)
  9. 9. FormEncode htmlfilldef hello(request): try: params = HelloSchema.to_python(request.params) except formencode.Invalid, e: res = index(request) res.text = htmlfill.render(res.body, request.params,errors=e.error_dict) return reshttp://formencode.org/
  10. 10. putting all togetherhttps://gist.github.com/1175051

×