Speed up development with full-stack environments for every branch.

Learn More

Request Method Dispatch in TurboGears [Python]

Forked from Parse JSON Data from Request in TurboGears.

42 Runs 149 Views 22 Copies
Saved

Saved

amol 16

amol
published 3 years ago

from wsgiref.simple_server import make_server
from tg import expose, TGController, RestController, AppConfig, request

# RestController dispatches requests based on the HTTP Method
class SayHelloController(RestController):
    @expose()
    def post(self):  # handles POST requests
      return 'HELLO POST'
      
    @expose()
    def get(self):  # handles GET requests
      return 'HELLO GET'


class RootController(TGController):
    # Use the SayHelloController to handle /hello requests
    # based on the request method.
    hello = SayHelloController()
    
    @expose('index.html')
    def index(self):
      return dict() 



config = AppConfig(minimal=True, root_controller=RootController())
config.renderers = ['genshi']

DEPLOY_OPTIONS = {}
httpd = make_server('', 80, config.make_wsgi_app(**DEPLOY_OPTIONS))

print "Serving on port 80..."
httpd.serve_forever()
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).