Created
December 8, 2016 13:27
-
-
Save zupo/859e09e76dec99a122b6dca55013b4f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Showcasing Pyramid's View Predicates. | |
Usage: | |
1. Install Pyramid: http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/install.html | |
2. Put this code into ``example.py``. | |
3. Run with ``$VENV/bin/python example.py``. | |
4. Showcase with your browser or using curl: | |
$ curl http://localhost:8080/ | |
Welcome! | |
$ curl --data "foo=bar" http://localhost:8080/ | |
What a nice POST! | |
""" | |
from pyramid.config import Configurator | |
from pyramid.response import Response | |
from pyramid.scripts.pserve import wsgiref_server_runner | |
from pyramid.view import view_config | |
@view_config( | |
route_name='home' | |
) | |
def home_get(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() | |
wsgiref_server_runner(config.make_wsgi_app(), None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment