Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created January 21, 2015 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanasco/4a27eb95549de771b304 to your computer and use it in GitHub Desktop.
Save jvanasco/4a27eb95549de771b304 to your computer and use it in GitHub Desktop.
pyramid and render_to_resposne
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.renderers import render_to_response, render
def json_bad(request):
return render_to_response('json', {'hello': 'world'})
def json_good(request):
return render_to_response('json', {'hello': 'world'}, request=request)
def main():
config = Configurator()
config.add_route('json:bad', '/json/bad')
config.add_view(json_bad, route_name='json:bad')
config.add_route('json:good', '/json/good')
config.add_view(json_good, route_name='json:good')
app = config.make_wsgi_app()
return app
if __name__ == '__main__':
app = main()
server = make_server('0.0.0.0', 6547, app)
print ('Starting up server on http://localhost:6547')
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment