Slide 1

Slide 1 text

Flask Workshop Miguel Grinberg @miguelgrinberg PyCon 2015

Slide 2

Slide 2 text

Who Am I? ● I work for Rackspace as an OpenStack engineer. ● I write about Flask, REST APIs, Robotics and more on my blog: http://blog.miguelgrinberg.com. ● I am the author of a few open source Flask extensions: Flask-HTTPAuth, Flask-SocketIO, Flask-Migrate, etc. ● I’m the author of the book Flask Web Development, and a few Flask training videos and webcasts, all for O’Reilly Media.

Slide 3

Slide 3 text

Agenda ● Why Flask? ● Setup ● Example Application Demonstration ● Let’s Build an Application ○ Hello, Flask! ○ Templates ○ Web Forms ○ User Sessions ○ Error handling ● What’s Next?

Slide 4

Slide 4 text

Why Flask? ● Small, lightweight, straightforward. ● Adapts easily to your way of thinking. ● Plays well with third party Python packages. ● Easy to build extensions (lots of extensions already available).

Slide 5

Slide 5 text

Setup ● Python Interpreter ○ Python 3.4 (recommended version) ○ Python 2.7 + virtualenv ● Git ● Reference code on Github ○ github.com/miguelgrinberg/flask-pycon2015.git ○ Incremental versions are tagged v0.1, v0.2, and so on.

Slide 6

Slide 6 text

Demo!

Slide 7

Slide 7 text

Hello, Flask! ● Create a project directory (or clone class project) ● Create a virtual environment ● Install Flask ● A “Hello, World” application v0.1 ● Add dynamic behavior v0.2 ● Make application accessible to other computers v0.3

Slide 8

Slide 8 text

Templates ● Why ○ To separate logic from presentation. ● How ○ Create HTML templates v0.4 ○ Create links between pages v0.5

Slide 9

Slide 9 text

Web Forms ● Why ○ To accept input from users ● How ○ Add a form to the application v0.6 ○ The Post-Redirect-Get pattern v0.7 ○ Using Flask-WTF and WTForms v0.8

Slide 10

Slide 10 text

Game Logic ● Why ○ Separation of concerns (again!) ● How ○ Add a module with the game logic v0.9 ○ Implement the end of the game v0.10 ○ Validate forms v0.11

Slide 11

Slide 11 text

User Sessions ● Why ○ To remember user state securely ● How ○ Store game state in the user session v0. 12

Slide 12

Slide 12 text

Error Handling ● Why ○ Because users are experts at finding bugs. ● How ○ Add error handler to the application v0. 13

Slide 13

Slide 13 text

What’s Next? ● Databases ● Authentication ● HTML/CSS Styling ● Structure for large applications ● Application Programming Interfaces (APIs) ● Rich client applications (Angular, Ember, React, etc.) ● Unit Testing ● Logging ● Beyond HTTP: WebSocket ● Deployment

Slide 14

Slide 14 text

@miguelgrinberg Thank You!