diff options
Diffstat (limited to 'docs/quick_tour/view_classes')
| -rw-r--r-- | docs/quick_tour/view_classes/app.py | 13 | ||||
| -rw-r--r-- | docs/quick_tour/view_classes/delete.jinja2 | 9 | ||||
| -rw-r--r-- | docs/quick_tour/view_classes/edit.jinja2 | 9 | ||||
| -rw-r--r-- | docs/quick_tour/view_classes/hello.jinja2 | 15 | ||||
| -rw-r--r-- | docs/quick_tour/view_classes/views.py | 30 |
5 files changed, 76 insertions, 0 deletions
diff --git a/docs/quick_tour/view_classes/app.py b/docs/quick_tour/view_classes/app.py new file mode 100644 index 000000000..40faddd00 --- /dev/null +++ b/docs/quick_tour/view_classes/app.py @@ -0,0 +1,13 @@ +from wsgiref.simple_server import make_server +from pyramid.config import Configurator + +if __name__ == '__main__': + config = Configurator() + 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('views') + app = config.make_wsgi_app() + server = make_server('0.0.0.0', 6543, app) + server.serve_forever() diff --git a/docs/quick_tour/view_classes/delete.jinja2 b/docs/quick_tour/view_classes/delete.jinja2 new file mode 100644 index 000000000..ba45b7d16 --- /dev/null +++ b/docs/quick_tour/view_classes/delete.jinja2 @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Delete World</title> +</head> +<body> +<h1>Delete {{ view.name }}!</h1> +</body> +</html>
\ No newline at end of file diff --git a/docs/quick_tour/view_classes/edit.jinja2 b/docs/quick_tour/view_classes/edit.jinja2 new file mode 100644 index 000000000..ce0eb5bd1 --- /dev/null +++ b/docs/quick_tour/view_classes/edit.jinja2 @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Edit World</title> +</head> +<body> +<h1>Edit {{ view.name }}!</h1> +</body> +</html>
\ No newline at end of file diff --git a/docs/quick_tour/view_classes/hello.jinja2 b/docs/quick_tour/view_classes/hello.jinja2 new file mode 100644 index 000000000..fc3058067 --- /dev/null +++ b/docs/quick_tour/view_classes/hello.jinja2 @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Hello World</title> +</head> +<body> +<h1>Hello {{ view.name }}!</h1> +<form method="POST" + action="{{ request.current_route_url() }}"> + <input name="new_name"> + <input type="submit" name="form.edit" value="Save"> + <input type="submit" name="form.delete" value="Delete"> +</form> +</body> +</html>
\ No newline at end of file diff --git a/docs/quick_tour/view_classes/views.py b/docs/quick_tour/view_classes/views.py new file mode 100644 index 000000000..10ff238c7 --- /dev/null +++ b/docs/quick_tour/view_classes/views.py @@ -0,0 +1,30 @@ +from pyramid.view import ( + view_config, + view_defaults + ) + + +# One route, at /howdy/amy, so don't repeat on each @view_config +@view_defaults(route_name='hello') +class HelloWorldViews: + def __init__(self, request): + self.request = request + # Our templates can now say {{ view.name }} + self.name = request.matchdict['name'] + + # Retrieving /howdy/amy the first time + @view_config(renderer='hello.jinja2') + def hello_view(self): + return dict() + + # Posting to /howdy/amy via the "Edit" submit button + @view_config(request_param='form.edit', renderer='edit.jinja2') + def edit_view(self): + print('Edited') + return dict() + + # Posting to /howdy/amy via the "Delete" submit button + @view_config(request_param='form.delete', renderer='delete.jinja2') + def delete_view(self): + print('Deleted') + return dict() |
