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


amol 16

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):
    def post(self):  # handles POST requests
      return 'HELLO POST'
    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()
    def index(self):
      return dict() 

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

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

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

Your session has timed out.

Dismiss (the page may not function properly).