the swiss army knife for python web developers
play

The Swiss-Army Knife for Python Web Developers Armin Ronacher - PowerPoint PPT Presentation

The Swiss-Army Knife for Python Web Developers Armin Ronacher http://lucumr.pocoo.org/ About Me About Me Name: Armin Ronacher Werkzeug, Jinja, Pygments, ubuntuusers.de Python since 2005 WSGI warrior since the very beginning


  1. #2: Configuration DATABASE = '/path/to/dumpit.db' PYGMENTS_STYLE = 'pastie' LANGUAGES = [ ('text', 'No Highlighting'), ('python', 'Python'), ('c', 'C') ] TEMPLATES = path.join(path.dirname(__file__), 'templates') jinja_env = Environment(loader=FileSystemLoader(TEMPLATES)) pygments_formatter = HtmlFormatter(style=PYGMENTS_STYLE) def render_template(template_name, **context): template = jinja_env.get_template(template_name) return template.render(context)

  2. #3: Dispatching

  3. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  4. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  5. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  6. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  7. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  8. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  9. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) http://localhost:5000/ def application(environ, start_response): http://localhost:5000/42 request = Request(environ) http://localhost:5000/42/raw request.db = sqlite3.connect(DATABASE) http://localhost:5000/pygments.css url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  10. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  11. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  12. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  13. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  14. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  15. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  16. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  17. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  18. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  19. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  20. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

  21. #3: Dispatching url_map = Map([ Rule('/', endpoint='new_paste'), Rule('/<int:id>', endpoint='show_paste'), Rule('/<int:id>/raw', endpoint='download_paste'), Rule('/pygments.css', endpoint='pygments_style') ]) def application(environ, start_response): request = Request(environ) request.db = sqlite3.connect(DATABASE) url_adapter = url_map.bind_to_environ(environ) try: endpoint, values = url_adapter.match() response = globals()[endpoint](request, **values) if isinstance(response, basestring): response = Response(response, mimetype='text/html') except HTTPException, error: response = error return response(environ, start_response)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend