From d559afa1b3fabe2733e97c64df4370cc12f33ce0 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Tue, 6 Aug 2013 15:23:51 -0400 Subject: Up through JSON. --- docs/getting_started/quick_glance/jinja2/app.py | 12 ++-------- .../quick_glance/jinja2/hello_world.jinja2 | 1 - docs/getting_started/quick_glance/jinja2/views.py | 8 +++++++ docs/getting_started/quick_glance/json/app.py | 15 ++----------- .../quick_glance/json/hello_world.jinja2 | 10 +++++++++ .../quick_glance/json/hello_world.pt | 17 ++++++++++++++ docs/getting_started/quick_glance/json/views.py | 13 +++++++++++ docs/getting_started/quick_glance/requests/app.py | 10 ++++++++- docs/getting_started/quick_glance/routing/app.py | 14 ++++-------- docs/getting_started/quick_glance/routing/views.py | 10 +++++++++ docs/getting_started/quick_glance/static/app.css | 4 ---- .../quick_glance/static_assets/app.py | 14 ++++++++++++ .../quick_glance/static_assets/hello_world.jinja2 | 10 +++++++++ .../quick_glance/static_assets/hello_world.pt | 17 ++++++++++++++ .../quick_glance/static_assets/static/app.css | 4 ++++ .../quick_glance/static_assets/views.py | 6 +++++ .../getting_started/quick_glance/templating/app.py | 10 +++++++++ .../quick_glance/templating/hello_world.pt | 8 +++++++ .../quick_glance/templating/views.py | 8 +++++++ .../quick_glance/view_classes/app.py | 2 +- docs/getting_started/quick_glance/views/app.py | 5 ++++- docs/getting_started/quick_glance/views/views.py | 26 ++++++++++++++++++++-- 22 files changed, 181 insertions(+), 43 deletions(-) create mode 100644 docs/getting_started/quick_glance/jinja2/views.py create mode 100644 docs/getting_started/quick_glance/json/hello_world.jinja2 create mode 100644 docs/getting_started/quick_glance/json/hello_world.pt create mode 100644 docs/getting_started/quick_glance/json/views.py create mode 100644 docs/getting_started/quick_glance/routing/views.py delete mode 100644 docs/getting_started/quick_glance/static/app.css create mode 100644 docs/getting_started/quick_glance/static_assets/app.py create mode 100644 docs/getting_started/quick_glance/static_assets/hello_world.jinja2 create mode 100644 docs/getting_started/quick_glance/static_assets/hello_world.pt create mode 100644 docs/getting_started/quick_glance/static_assets/static/app.css create mode 100644 docs/getting_started/quick_glance/static_assets/views.py create mode 100644 docs/getting_started/quick_glance/templating/app.py create mode 100644 docs/getting_started/quick_glance/templating/hello_world.pt create mode 100644 docs/getting_started/quick_glance/templating/views.py (limited to 'docs/getting_started/quick_glance') diff --git a/docs/getting_started/quick_glance/jinja2/app.py b/docs/getting_started/quick_glance/jinja2/app.py index bee50373b..83af219db 100644 --- a/docs/getting_started/quick_glance/jinja2/app.py +++ b/docs/getting_started/quick_glance/jinja2/app.py @@ -1,19 +1,11 @@ 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='hello', renderer='app3.jinja2') -def hello_world(request): - return dict(name=request.matchdict['name']) - if __name__ == '__main__': config = Configurator() - config.add_route('hello', '/hello/{name}') + config.add_route('hello', '/howdy/{name}') config.include('pyramid_jinja2') - config.scan() + config.scan('views') app = config.make_wsgi_app() server = make_server('0.0.0.0', 6543, app) server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/jinja2/hello_world.jinja2 b/docs/getting_started/quick_glance/jinja2/hello_world.jinja2 index 6d9f0cd5f..5fc1fc9bf 100644 --- a/docs/getting_started/quick_glance/jinja2/hello_world.jinja2 +++ b/docs/getting_started/quick_glance/jinja2/hello_world.jinja2 @@ -1,4 +1,3 @@ - Quick Glance diff --git a/docs/getting_started/quick_glance/jinja2/views.py b/docs/getting_started/quick_glance/jinja2/views.py new file mode 100644 index 000000000..916cdc720 --- /dev/null +++ b/docs/getting_started/quick_glance/jinja2/views.py @@ -0,0 +1,8 @@ +from pyramid.view import view_config + + +# Start View 1 +@view_config(route_name='hello', renderer='hello_world.jinja2') +# End View 1 +def hello_world(request): + return dict(name=request.matchdict['name']) diff --git a/docs/getting_started/quick_glance/json/app.py b/docs/getting_started/quick_glance/json/app.py index 9b47fdeaf..950cb478f 100644 --- a/docs/getting_started/quick_glance/json/app.py +++ b/docs/getting_started/quick_glance/json/app.py @@ -1,26 +1,15 @@ from wsgiref.simple_server import make_server from pyramid.config import Configurator -from pyramid.view import view_config - - -@view_config(route_name='hello', renderer='app4.jinja2') -def hello_world(request): - return dict(name=request.matchdict['name']) - - -@view_config(route_name='hello_json', renderer='json') -def hello_json(request): - return [1, 2, 3] if __name__ == '__main__': config = Configurator() - config.add_route('hello', '/hello/{name}') + config.add_route('hello', '/howdy/{name}') config.add_route('hello_json', 'hello.json') config.add_static_view(name='static', path='static') config.include('pyramid_jinja2') - config.scan() + config.scan('views') app = config.make_wsgi_app() server = make_server('0.0.0.0', 6543, app) server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/json/hello_world.jinja2 b/docs/getting_started/quick_glance/json/hello_world.jinja2 new file mode 100644 index 000000000..3d0f28c1f --- /dev/null +++ b/docs/getting_started/quick_glance/json/hello_world.jinja2 @@ -0,0 +1,10 @@ + + + + Quick Glance + + + +

Hello {{ name }}!

+ + \ No newline at end of file diff --git a/docs/getting_started/quick_glance/json/hello_world.pt b/docs/getting_started/quick_glance/json/hello_world.pt new file mode 100644 index 000000000..0cf20d076 --- /dev/null +++ b/docs/getting_started/quick_glance/json/hello_world.pt @@ -0,0 +1,17 @@ + + + + Quick Glance + + + + + + + + +

Hello ${name}!

+ + \ No newline at end of file diff --git a/docs/getting_started/quick_glance/json/views.py b/docs/getting_started/quick_glance/json/views.py new file mode 100644 index 000000000..583e220c7 --- /dev/null +++ b/docs/getting_started/quick_glance/json/views.py @@ -0,0 +1,13 @@ +from pyramid.view import view_config + + +@view_config(route_name='hello', renderer='hello_world.pt') +def hello_world(request): + return dict(name=request.matchdict['name']) + + +# Start View 1 +@view_config(route_name='hello_json', renderer='json') +def hello_json(request): + return [1, 2, 3] + # End View 1 \ No newline at end of file diff --git a/docs/getting_started/quick_glance/requests/app.py b/docs/getting_started/quick_glance/requests/app.py index df5a6cf18..7ac81eb50 100644 --- a/docs/getting_started/quick_glance/requests/app.py +++ b/docs/getting_started/quick_glance/requests/app.py @@ -4,7 +4,15 @@ from pyramid.response import Response def hello_world(request): - return Response('

Hello World!

') + # Some parameters from a request such as /?name=lisa + url = request.url + name = request.params.get('name', 'No Name Provided') + + body = 'URL %s with name: %s' % (url, name) + return Response( + content_type="text/plain", + body=body + ) if __name__ == '__main__': diff --git a/docs/getting_started/quick_glance/routing/app.py b/docs/getting_started/quick_glance/routing/app.py index bbae35b07..04a8a6344 100644 --- a/docs/getting_started/quick_glance/routing/app.py +++ b/docs/getting_started/quick_glance/routing/app.py @@ -1,18 +1,12 @@ 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='hello') -def hello_world(request): - return Response('

Hello %(name)s!

' % request.matchdict) - if __name__ == '__main__': config = Configurator() - config.add_route('hello', '/hello/{name}') - config.scan() + # Start Route 1 + config.add_route('hello', '/howdy/{first}/{last}') + # End Route 1 + config.scan('views') app = config.make_wsgi_app() server = make_server('0.0.0.0', 6543, app) server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/routing/views.py b/docs/getting_started/quick_glance/routing/views.py new file mode 100644 index 000000000..8cb8d3780 --- /dev/null +++ b/docs/getting_started/quick_glance/routing/views.py @@ -0,0 +1,10 @@ +from pyramid.response import Response +from pyramid.view import view_config + + +# Start Route 1 +@view_config(route_name='hello') +def hello_world(request): + body = '

Hi %(first)s %(last)s!

' % request.matchdict + return Response(body) + # End Route 1 \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static/app.css b/docs/getting_started/quick_glance/static/app.css deleted file mode 100644 index f8acf3164..000000000 --- a/docs/getting_started/quick_glance/static/app.css +++ /dev/null @@ -1,4 +0,0 @@ -body { - margin: 2em; - font-family: sans-serif; -} \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/app.py b/docs/getting_started/quick_glance/static_assets/app.py new file mode 100644 index 000000000..9c808972f --- /dev/null +++ b/docs/getting_started/quick_glance/static_assets/app.py @@ -0,0 +1,14 @@ +from wsgiref.simple_server import make_server +from pyramid.config import Configurator + +if __name__ == '__main__': + config = Configurator() + config.add_route('hello', '/howdy/{name}') + # Start Static 1 + config.add_static_view(name='static', path='static') + # End Static 1 + config.include('pyramid_jinja2') + config.scan('views') + app = config.make_wsgi_app() + server = make_server('0.0.0.0', 6543, app) + server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/hello_world.jinja2 b/docs/getting_started/quick_glance/static_assets/hello_world.jinja2 new file mode 100644 index 000000000..3d0f28c1f --- /dev/null +++ b/docs/getting_started/quick_glance/static_assets/hello_world.jinja2 @@ -0,0 +1,10 @@ + + + + Quick Glance + + + +

Hello {{ name }}!

+ + \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/hello_world.pt b/docs/getting_started/quick_glance/static_assets/hello_world.pt new file mode 100644 index 000000000..0cf20d076 --- /dev/null +++ b/docs/getting_started/quick_glance/static_assets/hello_world.pt @@ -0,0 +1,17 @@ + + + + Quick Glance + + + + + + + + +

Hello ${name}!

+ + \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/static/app.css b/docs/getting_started/quick_glance/static_assets/static/app.css new file mode 100644 index 000000000..f8acf3164 --- /dev/null +++ b/docs/getting_started/quick_glance/static_assets/static/app.css @@ -0,0 +1,4 @@ +body { + margin: 2em; + font-family: sans-serif; +} \ No newline at end of file diff --git a/docs/getting_started/quick_glance/static_assets/views.py b/docs/getting_started/quick_glance/static_assets/views.py new file mode 100644 index 000000000..90730ae32 --- /dev/null +++ b/docs/getting_started/quick_glance/static_assets/views.py @@ -0,0 +1,6 @@ +from pyramid.view import view_config + + +@view_config(route_name='hello', renderer='hello_world.pt') +def hello_world(request): + return dict(name=request.matchdict['name']) diff --git a/docs/getting_started/quick_glance/templating/app.py b/docs/getting_started/quick_glance/templating/app.py new file mode 100644 index 000000000..6d1a29f4e --- /dev/null +++ b/docs/getting_started/quick_glance/templating/app.py @@ -0,0 +1,10 @@ +from wsgiref.simple_server import make_server +from pyramid.config import Configurator + +if __name__ == '__main__': + config = Configurator() + config.add_route('hello', '/howdy/{name}') + config.scan('views') + app = config.make_wsgi_app() + server = make_server('0.0.0.0', 6543, app) + server.serve_forever() \ No newline at end of file diff --git a/docs/getting_started/quick_glance/templating/hello_world.pt b/docs/getting_started/quick_glance/templating/hello_world.pt new file mode 100644 index 000000000..8860df26a --- /dev/null +++ b/docs/getting_started/quick_glance/templating/hello_world.pt @@ -0,0 +1,8 @@ + + + Quick Glance + + +

Hello ${name}

+ + \ No newline at end of file diff --git a/docs/getting_started/quick_glance/templating/views.py b/docs/getting_started/quick_glance/templating/views.py new file mode 100644 index 000000000..6c7846efa --- /dev/null +++ b/docs/getting_started/quick_glance/templating/views.py @@ -0,0 +1,8 @@ +from pyramid.view import view_config + + +# Start View 1 +@view_config(route_name='hello', renderer='hello_world.pt') +def hello_world(request): + return dict(name=request.matchdict['name']) + # End View 1 \ No newline at end of file diff --git a/docs/getting_started/quick_glance/view_classes/app.py b/docs/getting_started/quick_glance/view_classes/app.py index 90978344b..c29311aa5 100644 --- a/docs/getting_started/quick_glance/view_classes/app.py +++ b/docs/getting_started/quick_glance/view_classes/app.py @@ -20,7 +20,7 @@ class HelloWorldViews: if __name__ == '__main__': config = Configurator() - config.add_route('hello', '/hello/{name}') + config.add_route('hello', '/howdy/{name}') config.add_route('hello_json', 'hello.json') config.add_static_view(name='static', path='static') config.include('pyramid_jinja2') diff --git a/docs/getting_started/quick_glance/views/app.py b/docs/getting_started/quick_glance/views/app.py index 1e12b6581..54dc9ed4b 100644 --- a/docs/getting_started/quick_glance/views/app.py +++ b/docs/getting_started/quick_glance/views/app.py @@ -3,7 +3,10 @@ from pyramid.config import Configurator if __name__ == '__main__': config = Configurator() - config.add_route('hello', '/hello/{name}') + config.add_route('home', '/') + config.add_route('hello', '/howdy') + config.add_route('redirect', '/goto') + config.add_route('exception', '/problem') config.scan('views') app = config.make_wsgi_app() server = make_server('0.0.0.0', 6543, app) diff --git a/docs/getting_started/quick_glance/views/views.py b/docs/getting_started/quick_glance/views/views.py index 53a6a273a..9dc795f14 100644 --- a/docs/getting_started/quick_glance/views/views.py +++ b/docs/getting_started/quick_glance/views/views.py @@ -1,7 +1,29 @@ +from pyramid.httpexceptions import HTTPFound from pyramid.response import Response from pyramid.view import view_config +# First view, available at http://localhost:6543/ +@view_config(route_name='home') +def home_view(request): + return Response('

Visit hello

') + + +# /howdy?name=alice which links to the next view @view_config(route_name='hello') -def hello_world(request): - return Response('

Hello %(name)s!

' % request.matchdict) +def hello_view(request): + name = request.params.get('name', 'No Name') + body = '

Hi %s, this redirects

' + return Response(body % name) + + +# /goto which issues HTTP redirect to the last view +@view_config(route_name='redirect') +def redirect_view(request): + return HTTPFound(location="/problem") + + +# /problem which causes an site error +@view_config(route_name='exception') +def exception_view(request): + raise Exception() -- cgit v1.2.3