Developing a web
 application with Flask

LAMP architecture

Linux, Apache, MySQL, PHP

Request

Response

We always do the same

  • CRUD (Create, Read, Update, Delete)

  • Read and parse GET and POST parameters

  • Handle users (register, login, password...)

  • Write HTML pages with a lot in common

 

Development principle: DRY (Don't Repeat Yourself)

Code organization: Model - View - Controller

Model - View - Controller

Frameworks

Microframeworks

Let's start!

Hangman game

Home

Hangman game

Play

Play!

Top 10

Hangman game

_ _ A _ _ A _ _O_

Errors: E, I

Try letter

|   

Steps

  1. Basic Flask application
  2. Database model and game logic
  3. Game page
  4. AJAX

1. Basic Flask application

  • Flask: route, render_template...
  • Jinja2 templates: extends, blocks...
  • Bootstrap: grid, form, ...
  • Developer tools (Ctrl + Shift + i)

2. Database model and game logic

  • SQLite
  • SQLAlchemy
  • Model in Python
  • Game logic: maximum 6 errors...

3. Game page

  • Create game
  • Process input letter
  • Render game

4. AJAX

AJAX

Asynchronous JavaScript and XML

 

                                                                       

Change web content without refreshing

4. AJAX

  • Send POST on submit
  • Update page content

Developing a web application with Flask

By victorlf

Developing a web application with Flask

  • 1,340