Building a Website with Python and Flask

Prerequisites

  • pip install flask

Basic app

And that’s it! You have your web app set.

Routes

What is routing? This route method simply binds functions to URL – when you visit that URL, the method will be executed server-side.

url_for

We can use url_for to redirect to another method:

Request types (GET / POST)

We can interrogate the request type and do specific things on each types:

Rendering templates

We can also render templates (webpage) using the render_template method.

Let’s see a more complex example. Let’s use render_template to send data from client to server side.

And the html could be something like this:

We can also configure the application and use data in the project:

Let’s see maybe a full function implementation.

What else we can do ?

Databases!

Want to see a full mini-project written in flask? Check this github page!

You may also like...

Leave a Reply