Professional Documents
Culture Documents
Web Framework(s)
keitheis
PycTW 2011
keitheis
@gmail.com
Software Developer
Web Developer
Python
ID Python Keith
Python Taiwan
PycTW 2011
web
ZH.Wikipedia:
200827
WebsiteHTML
-
199186
PycTW 2011
App Application
PycTW 2011
app
...
python
Python
1990 Guido van Rossum ( GvR BDFL)
TIOBE
2007
2010
PycTW 2011
http://wiki.python.org.tw/Python
print hello world?
PycTW 2011
hello world
hello world.[php|p6|py]
<? print hello world;
hello world.say;
print hello world
PycTW 2011
echo hello world;
PycTW 2011
<?php
hello.php
echo Fear, Uncertainty, and Doubt;
Apache
MySQL
PhP
PycTW 2011
FUD
FUD
echo FUD;
Apache
RewriteCond *.p* RewriteRule @@ = = > <
MySQL
mysql -e @racle$$$$$$$$$$$$$$$$$$QL
PhP
<? php //
PycTW 2011
pe
rl
6
ng
la
Go
Er
la
n
y
p
.
PycTW 2011
Exercise #50 on
PycTW 2011
PycTW 2011
import bottle
@bottle.route('/')
def index():
return 'Hello World'
bottle.run(host='localhost', port=8080)
PycTW 2011
app.py
PHP
Apache
MySQL
PHP
PycTW 2011
Python
PycTW 2011
Python
easy_installdistribute pip
Python 3
virtualenv
install bottle...
Window$
PycTW 2011
Python
Python
Python
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ python get-pip.py
$ pip install bottle
update: http://quest.keitheis.org/post/6713569631/pip-install-on-windows-linux-mac
PycTW 2011
yak shaving
XXX
PycTW 2011
http://learnpythonthehardway.org/book/ex46.html
Pyramid
PycTW 2011
Pylons Project
PycTW 2011
Pyramid
Pylons Project
Pylons & repoze.bfg Merger - or - Where'd Pylons 2.0 go?
https://groups.google.com/d/topic/pylons-discuss/l_qhijQpoo4/discussion
PycTW 2011
N ot Built by Aliens
http://wiki.python.org/moin/WebFrameworks
...
PycTW 2011
HTTPServer?
Paster
Tornado
nginx (uWSGI)
Apache
cherokee
PycTW 2011
web server
database
NoDatabase
To SQL
SQLite, PostgreSQL, MySQL, Percona...
Not to SQL (NoSQL)
redis, MongoDB, CouchDB, Hadoop, BigTable, Memcache...
PycTW 2011
template engine
PycTW 2011
http://blog.ez2learn.com/2010/01/27/introduction-to-wsgi/
GI
PSGI - Perl version of WSGI
Rack - Ruby version of WSGI
PycTW 2011
WSGI
Pylons
WSGI middleware
http://k0s.org/mozilla/craft/wsgi.png
2009 rz
Non-blocking WSGI
mailer
https://bitbucket.org/bbangert/kai/
Lamson web
a framework for building kickass email applications
http://amix.dk/blog/post/19608
PycTW 2011
HTTP
pip install Requests
testing HTTP
urllib?
r2 = requests.get(
'http://localhost:5000')
import requests
>>> r.headers['content-type']
r = requests.get(
'http://google.com')
>>> r.content
>>> r.status_code
request.put(...
401
request.delete(...
http://pypi.python.org/pypi/requests
PycTW 2011
Flask
Larger Applications
Application Factories
Template Inheritance
Application Dispatching
Message Flashing
SQLAlchemy in Flask
MongoKit in Flask
Uploading Files
Caching
View Decorators
PycTW 2011
http://flask.pocoo.org/docs/patterns/
MVC
SQL HTML
<!DOCTYPE html> <!-- HTML5 -->
<html><body>
<script>
<?phq $sql = select hours.* from my_time; ?>
var feel=<? $result = db->query($sql);
if ($result == $many) echo ; ?>;
alert(feel);
</script></body></html>
PycTW 2011
PycTW 2011