summaryrefslogtreecommitdiff
path: root/docs/getting_started/quick_glance
diff options
context:
space:
mode:
Diffstat (limited to 'docs/getting_started/quick_glance')
-rw-r--r--docs/getting_started/quick_glance/jinja2/app.py12
-rw-r--r--docs/getting_started/quick_glance/jinja2/hello_world.jinja21
-rw-r--r--docs/getting_started/quick_glance/jinja2/views.py8
-rw-r--r--docs/getting_started/quick_glance/json/app.py15
-rw-r--r--docs/getting_started/quick_glance/json/hello_world.jinja210
-rw-r--r--docs/getting_started/quick_glance/json/hello_world.pt17
-rw-r--r--docs/getting_started/quick_glance/json/views.py13
-rw-r--r--docs/getting_started/quick_glance/requests/app.py10
-rw-r--r--docs/getting_started/quick_glance/routing/app.py14
-rw-r--r--docs/getting_started/quick_glance/routing/views.py10
-rw-r--r--docs/getting_started/quick_glance/static_assets/app.py14
-rw-r--r--docs/getting_started/quick_glance/static_assets/hello_world.jinja210
-rw-r--r--docs/getting_started/quick_glance/static_assets/hello_world.pt17
-rw-r--r--docs/getting_started/quick_glance/static_assets/static/app.css (renamed from docs/getting_started/quick_glance/static/app.css)0
-rw-r--r--docs/getting_started/quick_glance/static_assets/views.py6
-rw-r--r--docs/getting_started/quick_glance/templating/app.py10
-rw-r--r--docs/getting_started/quick_glance/templating/hello_world.pt8
-rw-r--r--docs/getting_started/quick_glance/templating/views.py8
-rw-r--r--docs/getting_started/quick_glance/view_classes/app.py2
-rw-r--r--docs/getting_started/quick_glance/views/app.py5
-rw-r--r--docs/getting_started/quick_glance/views/views.py26
21 files changed, 177 insertions, 39 deletions
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 @@
-<html lang="en">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Quick Glance</title>
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 @@
+<html lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Quick Glance</title>
+ <link rel="stylesheet" href="/static/app.css" />
+</head>
+<body>
+<h1>Hello {{ name }}!</h1>
+</body>
+</html> \ 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 @@
+<html lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Quick Glance</title>
+ <!-- Start Link 1 -->
+ <link rel="stylesheet" href="/static/app.css" />
+ <!-- End Link 1 -->
+ <!-- Start Link 2 -->
+ <link rel="stylesheet"
+ href="${request.static_url('static/app.css')}"
+ />
+ <!-- End Link 2 -->
+</head>
+<body>
+<h1>Hello ${name}!</h1>
+</body>
+</html> \ 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('<h1>Hello World!</h1>')
+ # 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('<h1>Hello %(name)s!</h1>' % 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 = '<h1>Hi %(first)s %(last)s!</h1>' % request.matchdict
+ return Response(body)
+ # End Route 1 \ 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 @@
+<html lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Quick Glance</title>
+ <link rel="stylesheet" href="/static/app.css" />
+</head>
+<body>
+<h1>Hello {{ name }}!</h1>
+</body>
+</html> \ 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 @@
+<html lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Quick Glance</title>
+ <!-- Start Link 1 -->
+ <link rel="stylesheet" href="/static/app.css" />
+ <!-- End Link 1 -->
+ <!-- Start Link 2 -->
+ <link rel="stylesheet"
+ href="${request.static_url('static/app.css')}"
+ />
+ <!-- End Link 2 -->
+</head>
+<body>
+<h1>Hello ${name}!</h1>
+</body>
+</html> \ No newline at end of file
diff --git a/docs/getting_started/quick_glance/static/app.css b/docs/getting_started/quick_glance/static_assets/static/app.css
index f8acf3164..f8acf3164 100644
--- a/docs/getting_started/quick_glance/static/app.css
+++ b/docs/getting_started/quick_glance/static_assets/static/app.css
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 @@
+<html lang="en">
+<head>
+ <title>Quick Glance</title>
+</head>
+<body>
+<h1>Hello ${name}</h1>
+</body>
+</html> \ 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('<p>Visit <a href="/howdy?name=lisa">hello</a></p>')
+
+
+# /howdy?name=alice which links to the next view
@view_config(route_name='hello')
-def hello_world(request):
- return Response('<h1>Hello %(name)s!</h1>' % request.matchdict)
+def hello_view(request):
+ name = request.params.get('name', 'No Name')
+ body = '<p>Hi %s, this <a href="/goto">redirects</a></p>'
+ 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()