Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flask Workshop - PyCon 2015

Flask Workshop - PyCon 2015

(Presented at PyCon 2015)
Watch here: https://www.youtube.com/watch?v=DIcpEg77gdE

Flask is a web framework for Python based on Werkzeug, Jinja 2 and good intentions. It is considered a micro-framework, but don't get the "micro" part fool you; Flask can do everything others can do, many times in a simpler, leaner way. In this tutorial session we will build a web application together. Bring your laptop and your questions!

Avatar for Miguel Grinberg

Miguel Grinberg

April 08, 2015
Tweet

More Decks by Miguel Grinberg

Other Decks in Programming

Transcript

  1. 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.
  2. Agenda • Why Flask? • Setup • Example Application Demonstration

    • Let’s Build an Application ◦ Hello, Flask! ◦ Templates ◦ Web Forms ◦ User Sessions ◦ Error handling • What’s Next?
  3. 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).
  4. 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.
  5. 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
  6. Templates • Why ◦ To separate logic from presentation. •

    How ◦ Create HTML templates v0.4 ◦ Create links between pages v0.5
  7. 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
  8. 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
  9. User Sessions • Why ◦ To remember user state securely

    • How ◦ Store game state in the user session v0. 12
  10. Error Handling • Why ◦ Because users are experts at

    finding bugs. • How ◦ Add error handler to the application v0. 13
  11. 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