Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple Pyramid app with a counter using views, routes, and templates.
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
count = 0
def counter_view(request):
global count
action = request.params.get('action')
if action == 'increment': count += 1
elif action == 'decrement': count -= 1
elif action == 'reset': count = 0
return Response(f'''
<html>
<head><title>Pyramid Counter</title></head>
<body>
<h2>Counter: {count}</h2>
<form method='get'>
<button name='action' value='increment'>+</button>
<button name='action' value='decrement'>-</button>
<button name='action' value='reset'>Reset</button>
</form>
</body>
</html>
''')
if __name__ == '__main__':
with Configurator() as config:
config.add_route('counter', '/counter')
config.add_view(counter_view, route_name='counter')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 6543, app)
print('Pyramid server running at http://localhost:6543/counter')
server.serve_forever()Pyramid is a lightweight, flexible Python web framework that emphasizes minimalism and modularity. It allows developers to choose their own components for templating, database, and authentication.
Origin & Creator
Pyramid was created by Agendaless Consulting and initially released by Chris McDonough, Michael Merickel, and the Pylons Project team in 2005.
Industrial Note
Pyramid is ideal for projects where flexibility, minimalism, and choice of components matter-common in APIs, research apps, and modular enterprise systems.