Skip to content

Instantly share code, notes, and snippets.

@zupo
Created December 7, 2016 10:17
Show Gist options
  • Save zupo/4a99f185818a1f2fdc846a152286abda to your computer and use it in GitHub Desktop.
Save zupo/4a99f185818a1f2fdc846a152286abda to your computer and use it in GitHub Desktop.
Example 2
"""
* Put this code into home.py
* Install Pyramid.
* Run ``$ python home.py``.
* Point your browser to http://localhost:8080/
* Make a POST request with curl: $ curl --data "" http://localhost:8080/
"""
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config
@view_config(
route_name='home'
)
def home(request):
return Response('Welcome!')
@view_config(
route_name='home',
request_method=('POST')
)
def home(request):
return Response('What a nice POST!')
if __name__ == '__main__':
config = Configurator()
config.add_route('home', '/')
config.scan()
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment