How to create a basic Flask web page

Manpreet Singh
4 min readApr 30, 2021

Welcome back! Flask is a very popular web framework for web development using Python, so let’s build a basic web page using Flask!

Installation

Starting off we’re going to have to install Flask, to do this we’ll use pip:

pip install flask
#OR
pip3 install flask

Awesome! Creating a Flask web page is just like creating a standard python script, unlike Django which is a bit more complicated. Starting off, our Python script must import the specific Flask package, to do this use the following import line:

from flask import Flask

Next up we want to initialize our flask application, to do so we use the following line:

app = Flask(__name__)

The __name__ portion just tells Python that we’re making a Flask app. now we want our webpage to display something on the main page, to do this use the following line:

@app.route("/")

This pretty much declares what portion of the website is going to display the code we have written, if our website was google.com, it would display the contents at google.com/, pretty much the home page.Let’s do another example, let’s say our domain was google.com, let’s say we made our app.route this instead:

--

--

Manpreet Singh
Manpreet Singh

Responses (1)