SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
Python Web
Microframework
     Markus Zapke-Gründemann
Leipzig Python User Group - 8.9.2009
Web Microframework
Python 2.5 oder 3.x
WSGI
(Web Server Gateway Interface)
Routing
POST, GET, PUT,
DELETE, HEAD
Cookies
Templates
Einfache Validatoren
Key/Value Datenbank
1 Datei
936 Zeilen
30460 Byte
MIT Lizenz
GitHub
bottle.paws.de
Beispiel 1
1   from bottle import route, run
2
3   @route('/')
4   def index():
5       return 'Hello World!'
6
7   run()
Beispiel 2
1   from bottle import route, run
2
3   @route('/hello/:name')
4   def index(name):
5       return 'Hello %s!' % name
6
7   run()
Beispiel 3
1   from bottle import route, run, send_file
2
3   @route('/static/:filename')
4   def static_file(filename):
5       send_file(filename, root='/path/to/static/files')
6
7   run()
Beispiel 4
1   from bottle import route, run, send_file
2
3   @route(r'/static/(?P<filename>.*)')
4   def static_file(filename):
5       send_file(filename, root='/path/to/static/files')
6
7   run()
Beispiel 5
1   from bottle import route, run, template
2
3   @route('/welcome/:names')
4   def welcome(names):
5       names = names.split(',')
6       return template('welcome', names=names)
7
8   run()


 1 <html>
 2     <head>
 3         <title>Welcome!</title>
 4     </head>
 5     <body>
 6         <h1>Welcome!</h1>
 7         %for name in names:
 8         <p>Hello {{name}}!</p>
 9         %end
10     </body>
11 </html>
Beispiel 6
1   from bottle import request, route, run
2
3   @route('/user-agent')
4   def user_agent():
5       return request._environ.get('HTTP_USER_AGENT')
6
7   run()
Beispiel 7
 1   from bottle import route, run
 2
 3   @route(r'/get_object/(?P<id>[0-9]+)')
 4   def get_id(id):
 5       return "Object ID: %d" % int(id)
 6
 7   @route(r'/get_object/(?P<slug>[-w]+)')
 8   def get_slug(slug):
 9       return "Slug: %s" % slug
10
11   run()
Beispiel 8
1   from bottle import route, run, validate
2
3   @route('/validate/:id/:price/:csv')
4   @validate(id=int, price=float, csv=lambda x: map(int, x.split(',')))
5   def validate_args(id, price, csv):
6       return "Id: %d, Price: %f, List: %s" % (id, price, repr(csv))
7
8   run()
Lizenz
 Dieses Werk ist unter einem Creative Commons
    Namensnennung-Weitergabe unter gleichen
Bedingungen 3.0 Unported Lizenzvertrag lizenziert.
    Um die Lizenz anzusehen, gehen Sie bitte zu
http://creativecommons.org/licenses/by-sa/3.0/ oder
schicken Sie einen Brief an Creative Commons, 171
 Second Street, Suite 300, San Francisco, California
                    94105, USA.

Más contenido relacionado

Destacado

NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - AperturaWEBdeBS
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia ContiniWEBdeBS
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCMindfire Solutions
 
The Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyThe Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyTzu-ping Chung
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & PostgresqlLucio Grenzi
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - ChiusuraWEBdeBS
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesMarkus Zapke-Gründemann
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘Jiho Lee
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at PyconJacqueline Kazil
 
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to pythonJiho Lee
 

Destacado (19)

NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
 
Vim for Mere Mortals
Vim for Mere MortalsVim for Mere Mortals
Vim for Mere Mortals
 
Load testing
Load testingLoad testing
Load testing
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
 
The Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyThe Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.py
 
Html5 History-API
Html5 History-APIHtml5 History-API
Html5 History-API
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & Postgresql
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘
 
User-centered open source
User-centered open sourceUser-centered open source
User-centered open source
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at Pycon
 
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python
 
EuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein RückblickEuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein Rückblick
 

Similar a Bottle - Python Web Microframework

entwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den Wolkenentwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den WolkenJan Stamer
 
Infizierter Shop. Eine Magento Case Study
Infizierter Shop. Eine Magento Case StudyInfizierter Shop. Eine Magento Case Study
Infizierter Shop. Eine Magento Case StudyTUDOCK GmbH
 
Nutze die Macht @ IKT-Forum 09 Linz
Nutze die Macht @ IKT-Forum 09 LinzNutze die Macht @ IKT-Forum 09 Linz
Nutze die Macht @ IKT-Forum 09 LinzEric Eggert
 
IPC 2015 Zend Framework 3 Reloaded
IPC 2015 Zend Framework 3 ReloadedIPC 2015 Zend Framework 3 Reloaded
IPC 2015 Zend Framework 3 ReloadedRalf Eggert
 

Similar a Bottle - Python Web Microframework (6)

Web-Services mit Go
Web-Services mit GoWeb-Services mit Go
Web-Services mit Go
 
entwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den Wolkenentwickler.de 05/2023: Go über den Wolken
entwickler.de 05/2023: Go über den Wolken
 
Infizierter Shop. Eine Magento Case Study
Infizierter Shop. Eine Magento Case StudyInfizierter Shop. Eine Magento Case Study
Infizierter Shop. Eine Magento Case Study
 
Web Entwicklung mit PHP - Teil 1
Web Entwicklung mit PHP - Teil 1Web Entwicklung mit PHP - Teil 1
Web Entwicklung mit PHP - Teil 1
 
Nutze die Macht @ IKT-Forum 09 Linz
Nutze die Macht @ IKT-Forum 09 LinzNutze die Macht @ IKT-Forum 09 Linz
Nutze die Macht @ IKT-Forum 09 Linz
 
IPC 2015 Zend Framework 3 Reloaded
IPC 2015 Zend Framework 3 ReloadedIPC 2015 Zend Framework 3 Reloaded
IPC 2015 Zend Framework 3 Reloaded
 

Más de Markus Zapke-Gründemann

Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using SphinxMarkus Zapke-Gründemann
 
Sichere Web-Applikationen am Beispiel von Django
Sichere Web-Applikationen am Beispiel von DjangoSichere Web-Applikationen am Beispiel von Django
Sichere Web-Applikationen am Beispiel von DjangoMarkus Zapke-Gründemann
 
Virtuelle Maschinen mit Packer, Vagrant und Salt bauen
Virtuelle Maschinen mit Packer, Vagrant und Salt bauenVirtuelle Maschinen mit Packer, Vagrant und Salt bauen
Virtuelle Maschinen mit Packer, Vagrant und Salt bauenMarkus Zapke-Gründemann
 
Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using SphinxMarkus Zapke-Gründemann
 
Celery eine asynchrone task queue (nicht nur) für django
Celery   eine asynchrone task queue (nicht nur) für djangoCelery   eine asynchrone task queue (nicht nur) für django
Celery eine asynchrone task queue (nicht nur) für djangoMarkus Zapke-Gründemann
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvMarkus Zapke-Gründemann
 
Celery - eine asynchrone Task Queue (nicht nur) für Django
Celery - eine asynchrone Task Queue (nicht nur) für DjangoCelery - eine asynchrone Task Queue (nicht nur) für Django
Celery - eine asynchrone Task Queue (nicht nur) für DjangoMarkus Zapke-Gründemann
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvMarkus Zapke-Gründemann
 
Bottle - Python Web Microframework (english)
Bottle - Python Web Microframework (english)Bottle - Python Web Microframework (english)
Bottle - Python Web Microframework (english)Markus Zapke-Gründemann
 

Más de Markus Zapke-Gründemann (10)

Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using Sphinx
 
Sichere Web-Applikationen am Beispiel von Django
Sichere Web-Applikationen am Beispiel von DjangoSichere Web-Applikationen am Beispiel von Django
Sichere Web-Applikationen am Beispiel von Django
 
Virtuelle Maschinen mit Packer, Vagrant und Salt bauen
Virtuelle Maschinen mit Packer, Vagrant und Salt bauenVirtuelle Maschinen mit Packer, Vagrant und Salt bauen
Virtuelle Maschinen mit Packer, Vagrant und Salt bauen
 
Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using Sphinx
 
Mercurial
MercurialMercurial
Mercurial
 
Celery eine asynchrone task queue (nicht nur) für django
Celery   eine asynchrone task queue (nicht nur) für djangoCelery   eine asynchrone task queue (nicht nur) für django
Celery eine asynchrone task queue (nicht nur) für django
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Celery - eine asynchrone Task Queue (nicht nur) für Django
Celery - eine asynchrone Task Queue (nicht nur) für DjangoCelery - eine asynchrone Task Queue (nicht nur) für Django
Celery - eine asynchrone Task Queue (nicht nur) für Django
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Bottle - Python Web Microframework (english)
Bottle - Python Web Microframework (english)Bottle - Python Web Microframework (english)
Bottle - Python Web Microframework (english)
 

Bottle - Python Web Microframework

  • 1. Python Web Microframework Markus Zapke-Gründemann Leipzig Python User Group - 8.9.2009
  • 2.
  • 16. Beispiel 1 1 from bottle import route, run 2 3 @route('/') 4 def index(): 5 return 'Hello World!' 6 7 run()
  • 17. Beispiel 2 1 from bottle import route, run 2 3 @route('/hello/:name') 4 def index(name): 5 return 'Hello %s!' % name 6 7 run()
  • 18. Beispiel 3 1 from bottle import route, run, send_file 2 3 @route('/static/:filename') 4 def static_file(filename): 5 send_file(filename, root='/path/to/static/files') 6 7 run()
  • 19. Beispiel 4 1 from bottle import route, run, send_file 2 3 @route(r'/static/(?P<filename>.*)') 4 def static_file(filename): 5 send_file(filename, root='/path/to/static/files') 6 7 run()
  • 20. Beispiel 5 1 from bottle import route, run, template 2 3 @route('/welcome/:names') 4 def welcome(names): 5 names = names.split(',') 6 return template('welcome', names=names) 7 8 run() 1 <html> 2 <head> 3 <title>Welcome!</title> 4 </head> 5 <body> 6 <h1>Welcome!</h1> 7 %for name in names: 8 <p>Hello {{name}}!</p> 9 %end 10 </body> 11 </html>
  • 21. Beispiel 6 1 from bottle import request, route, run 2 3 @route('/user-agent') 4 def user_agent(): 5 return request._environ.get('HTTP_USER_AGENT') 6 7 run()
  • 22. Beispiel 7 1 from bottle import route, run 2 3 @route(r'/get_object/(?P<id>[0-9]+)') 4 def get_id(id): 5 return "Object ID: %d" % int(id) 6 7 @route(r'/get_object/(?P<slug>[-w]+)') 8 def get_slug(slug): 9 return "Slug: %s" % slug 10 11 run()
  • 23. Beispiel 8 1 from bottle import route, run, validate 2 3 @route('/validate/:id/:price/:csv') 4 @validate(id=int, price=float, csv=lambda x: map(int, x.split(','))) 5 def validate_args(id, price, csv): 6 return "Id: %d, Price: %f, List: %s" % (id, price, repr(csv)) 7 8 run()
  • 24. Lizenz Dieses Werk ist unter einem Creative Commons Namensnennung-Weitergabe unter gleichen Bedingungen 3.0 Unported Lizenzvertrag lizenziert. Um die Lizenz anzusehen, gehen Sie bitte zu http://creativecommons.org/licenses/by-sa/3.0/ oder schicken Sie einen Brief an Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.