Python Web
Microframework
 Markus Zapke-Gründemann
        RuPy 2009
Web Microframework
Python 2.5 or 3.x
WSGI
(Web Server Gateway Interface)
Google AppEngine
Routing
POST, GET, PUT,
DELETE, HEAD
Cookies
Templates
Simple Validators
Key/Value Database
JSON
1 File
1228 Lines
40019 Byte
MIT License
GitHub
bottle.paws.de
Example 1
1   from bottle import route, run
2
3   @route('/')
4   def index():
5       return 'Hello World!'
6
7   run()
Example 2
1   from bottle import route, run
2
3   @route('/hello/:name')
4   def index(name):
5       return 'Hello %s!' %...
Example 3
1   from bottle import route, run, send_file
2
3   @route('/static/:filename')
4   def static_file(filename):
5 ...
Example 4
1   from bottle import route, run, send_file
2
3   @route(r'/static/(?P<filename>.*)')
4   def static_file(filen...
Example 5
1   from bottle import route, run, template
2
3   @route('/welcome/:names')
4   def welcome(names):
5       name...
Example 6
1   from bottle import request, route, run
2
3   @route('/user-agent')
4   def user_agent():
5       return requ...
Example 7
 1   from bottle import route, run
 2
 3   @route(r'/get_object/(?P<id>[0-9]+)')
 4   def get_id(id):
 5       r...
Example 8
1   from bottle import route, run, validate
2
3   @route('/validate/:id/:price/:csv')
4   @validate(id=int, pric...
License
This work is licensed under the Creative Commons
   Attribution-Share Alike 3.0 Unported License.
         To view...
Bottle - Python Web Microframework (english)
Upcoming SlideShare
Loading in …5
×

Bottle - Python Web Microframework (english)

4,687 views

Published on

Lighting talk held at RuPy 2009.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,687
On SlideShare
0
From Embeds
0
Number of Embeds
102
Actions
Shares
0
Downloads
63
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Bottle - Python Web Microframework (english)

  1. 1. Python Web Microframework Markus Zapke-Gründemann RuPy 2009
  2. 2. Web Microframework
  3. 3. Python 2.5 or 3.x
  4. 4. WSGI (Web Server Gateway Interface)
  5. 5. Google AppEngine
  6. 6. Routing
  7. 7. POST, GET, PUT, DELETE, HEAD
  8. 8. Cookies
  9. 9. Templates
  10. 10. Simple Validators
  11. 11. Key/Value Database
  12. 12. JSON
  13. 13. 1 File 1228 Lines 40019 Byte
  14. 14. MIT License
  15. 15. GitHub
  16. 16. bottle.paws.de
  17. 17. Example 1 1 from bottle import route, run 2 3 @route('/') 4 def index(): 5 return 'Hello World!' 6 7 run()
  18. 18. Example 2 1 from bottle import route, run 2 3 @route('/hello/:name') 4 def index(name): 5 return 'Hello %s!' % name 6 7 run()
  19. 19. Example 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()
  20. 20. Example 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()
  21. 21. Example 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>
  22. 22. Example 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()
  23. 23. Example 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()
  24. 24. Example 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()
  25. 25. License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

×