Slide 1

Slide 1 text

SNAKES ON THE WEB Jacob Kaplan-Moss [email protected] The history and future of Python on the web http://www.flickr.com/photos/kejhu/3751877257 2012

Slide 2

Slide 2 text

㿄 http://jacobian.org/writing/snakes-on-the-web/

Slide 3

Slide 3 text

Web development SUCKS

Slide 4

Slide 4 text

How can I make it SUCK LESS?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

1. What sucks now?

Slide 7

Slide 7 text

1. What sucks now? 2. How will we fix it?

Slide 8

Slide 8 text

1. What sucks now? 2. How will we fix it? 3. Can we fix it with Python?

Slide 9

Slide 9 text

http://www.flickr.com/photos/tonythemisfit/2904911703 In the beginning…

Slide 10

Slide 10 text

Hand-rolled HTML “The Stone Age”

Appendix A: Model Definition Reference

Chapter 5 explains the basics of defining models, and we use them throughout the rest of the book. There is, however, a huge range of model options available not covered elsewhere. This appendix explains each possible model definition option.

Note that although these APIs are considered stable, the Django developers consistently add new shortcuts and conveniences to the model definition. It’s a good idea to always check the latest documentation online at http://docs.djangoproject.com/.

Fields

The most important part of a model – and the only required part of a model – is the list of database fields it defines.

Field Name Restrictions

Django places only two restrictions on model field names:

  1. A field name cannot be a Python reserved word, because that would result in a Python syntax error. For example:

    class Example(models.Model):
    pass = models.IntegerField() # 'pass' is a reserved word!
  2. A field name cannot contain more than one underscore in a row, due to the way Django’s query lookup syntax works. For example:

    class Example(
    span>models.Model):
    foo__bar = models.IntegerField() # 'foo__bar' has two underscores!
    

These limitations can be worked around, though, because your field name doesn’t necessarily have to match your database column name. See “db_column”, below.

SQL reserved words, such as join, where, or select, are allowed as model field names, because Django escapes all database table names and column names in every underlying SQL query. It uses the quoting syntax of your particular database engine.

Each field in your model should be an instance of the appropriate Field class. Django uses the field class types to determine a few things:

  • The database column type (e.g., INTEGER, VARCHAR).
  • The widget to use in Django’s forms and admin site, if you care to use it (e.g., <input type="text">, <select>).
  • The minimal validation requirements, which are used in Django’s admin interface and by forms.

A complete list of field classes follows, sorted alphabetically. Note that relationship fields (ForeignKey, etc.) are handled in the next section.

Slide 11

Slide 11 text

SUCK.

Appendix A: Model Definition Reference

Chapter 5 explains the basics of defining models, and we use them throughout the rest of the book. There is, however, a huge range of model options available not covered elsewhere. This appendix explains each possible model definition option.

Note that although these APIs are considered stable, the Django developers consistently add new shortcuts and conveniences to the model definition. It’s a good idea to always check the latest documentation online at http://docs.djangoproject.com/.

Fields

The most important part of a model – and the only required part of a model – is the list of database fields it defines.

Field Name Restrictions

Django places only two restrictions on model field names:

  1. A field name cannot be a Python reserved word, because that would result in a Python syntax error. For example:

    class Example(models.Model):
    pass = models.IntegerField() # 'pass' is a reserved word!
  2. A field name cannot contain more than one underscore in a row, due to the way Django’s query lookup syntax works. For example:

    class Example(
    span>models.Model):
    foo__bar = models.IntegerField() # 'foo__bar' has two underscores!
    

These limitations can be worked around, though, because your field name doesn’t necessarily have to match your database column name. See “db_column”, below.

SQL reserved words, such as join, where, or select, are allowed as model field names, because Django escapes all database table names and column names in every underlying SQL query. It uses the quoting syntax of your particular database engine.

Each field in your model should be an instance of the appropriate Field class. Django uses the field class types to determine a few things:

  • The database column type (e.g., INTEGER, VARCHAR).
  • The widget to use in Django’s forms and admin site, if you care to use it (e.g., <input type="text">, <select>).
  • The minimal validation requirements, which are used in Django’s admin interface and by forms.

A complete list of field classes follows, sorted alphabetically. Note that relationship fields (ForeignKey, etc.) are handled in the next section.

Slide 12

Slide 12 text

CGI “The Bronze Age” use CGI; my $q = CGI->new; # Process an HTTP request @values = $q->param('form_field'); $fh = $q->upload('file_field'); $riddle = $query->cookie('riddle_name'); %answers = $query->cookie('answers'); # Prepare various HTTP responses print $q->header(); print $q->header('application/json'); $cookie1 = $q->cookie(-name=>'riddle_name', -value=>"The Sphynx's Question"); $cookie2 = $q->cookie(-name=>'answers', -value=>\%answers); print $q->header( -type => 'image/gif', -expires => '+3d', -cookie => [$cookie1,$cookie2] ); print $q->redirect('http://somewhere.else/in/movie/land');

Slide 13

Slide 13 text

SUCK. use CGI; my $q = CGI->new; # Process an HTTP request @values = $q->param('form_field'); $fh = $q->upload('file_field'); $riddle = $query->cookie('riddle_name'); %answers = $query->cookie('answers'); # Prepare various HTTP responses print $q->header(); print $q->header('application/json'); $cookie1 = $q->cookie(-name=>'riddle_name', -value=>"The Sphynx's Question"); $cookie2 = $q->cookie(-name=>'answers', -value=>\%answers); print $q->header( -type => 'image/gif', -expires => '+3d', -cookie => [$cookie1,$cookie2] ); print $q->redirect('http://somewhere.else/in/movie/land');

Slide 14

Slide 14 text

PHP “The Iron Age”

Slide 15

Slide 15 text

Same idea, (slightly) better tech. http://www.flickr.com/photos/jerhoyet/2377140741

Slide 16

Slide 16 text

http://www.flickr.com/photos/just_jump/2972461681 Page-oriented

Slide 17

Slide 17 text

Rdio.app

Slide 18

Slide 18 text

Frameworks “The Industrial Revolution”

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

The modern web framework:

Slide 21

Slide 21 text

http://www.flickr.com/photos/nikonvscanon/2128705916 High-level

Slide 22

Slide 22 text

http://www.flickr.com/photos/joelaz/2868356069 Application-oriented

Slide 23

Slide 23 text

http://www.flickr.com/photos/ppdigital/2329405081/ Large blocks

Slide 24

Slide 24 text

http://www.flickr.com/photos/jasephotos/2913135232/ Rapid development

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

http://www.flickr.com/photos/nattu/1190083977 Fun!

Slide 27

Slide 27 text

What comes NEXT?

Slide 28

Slide 28 text

What problems SUCK NOW?

Slide 29

Slide 29 text

Interoperability SUCKS.

Slide 30

Slide 30 text

http://www.flickr.com/photos/amberandclint/3266859324/ Frameworks: good

Slide 31

Slide 31 text

Lock-in: bad! http://www.flickr.com/photos/striatic/2191404675/

Slide 32

Slide 32 text

Rule 1: Don’t piss off your users.

Slide 33

Slide 33 text

Software becomes domain-specific.

Slide 34

Slide 34 text

Cede control gracefully. http://www.flickr.com/photos/aidan_jones/3575000735

Slide 35

Slide 35 text

http://www.flickr.com/photos/kpwerker/421386062/ Fram ew ork inter-op

Slide 36

Slide 36 text

We CAN find areas in common

Slide 37

Slide 37 text

Rich applications SUCK.

Slide 38

Slide 38 text

HTML 5

Slide 39

Slide 39 text

The best thing to happen to WEB FRAMEWORKS?

Slide 40

Slide 40 text

http://www.flickr.com/photos/oskay/156280584/ Current frameworks don’t fit.

Slide 41

Slide 41 text

“Real-time”

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

This is the future.

Slide 46

Slide 46 text

Is real-time possible in PYTHON?

Slide 47

Slide 47 text

Yes! But. https://github.com/ptone/django-live

Slide 48

Slide 48 text

Traditional Django app

Slide 49

Slide 49 text

Real-time Django REDIS SOCKET IO GEVENT BACKBONE

Slide 50

Slide 50 text

Django

Slide 51

Slide 51 text

Django 750 lines of code

Slide 52

Slide 52 text

Django 750 lines of code 18 external libraries

Slide 53

Slide 53 text

Django 750 lines of code 18 external libraries 4 running services

Slide 54

Slide 54 text

Django 750 lines of code 18 external libraries 4 running services Meteor

Slide 55

Slide 55 text

Django 750 lines of code 18 external libraries 4 running services Meteor 12 lines of code

Slide 56

Slide 56 text

Django 750 lines of code 18 external libraries 4 running services Meteor 12 lines of code 0 external libraries

Slide 57

Slide 57 text

Django 750 lines of code 18 external libraries 4 running services Meteor 12 lines of code 0 external libraries 1 running service

Slide 58

Slide 58 text

Is real-time possible in PYTHON?

Slide 59

Slide 59 text

Is real-time EASY in Python?

Slide 60

Slide 60 text

Concurrency SUCKS.

Slide 61

Slide 61 text

http://www.flickr.com/photos/marc_buehler/3053243413 All roads lead to multi-core

Slide 62

Slide 62 text

Sparc T4

Slide 63

Slide 63 text

256 hardware threads

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

TWISTED & TORNADO & GEVENT & EVENTLET & ...

Slide 66

Slide 66 text

Actors STM PDS Dataflow Threads Events Tuple spaces Ted Leung, A survey of concurrency constructs: http://tinyurl.com/mmbqe6

Slide 67

Slide 67 text

Help!

Slide 68

Slide 68 text

2020

Slide 69

Slide 69 text

I want to be using PYTHON!

Slide 70

Slide 70 text

“ ” Good software takes ten years. Get used to it. — Joel Spolsky http://tinyurl.com/ca4pr

Slide 71

Slide 71 text

So we need to START NOW!

Slide 72

Slide 72 text

THANK YOU! Jacob Kaplan-Moss [email protected] http://www.flickr.com/photos/kejhu/3751877257