Hello World Basic Flask App

PURPOSE

To start hosting your Python Apps on a Webserver, you would first need to deploy it locally.

The starting point of any such project, is to create a basic web server, and host your app on your machine's localhost (127.0.0.1).

This article is intended to be a Hello World project for such a use case

The Author assumes that you have some basic understanding of working with Python 3.

Step 0: [Optional] Creating a virtual environment

If you're on Windows, open command prompt and type:

Step 1: INITIAL SETUP

Installing Flask framework using pip

Create a new project directory, and open a file named app.py inside it.

Step 2: CODING YOUR FIRST FLASK APP

Add the following to the app.py file:

Run the app.py file.

  • Your command prompt will be telling you that a server is up and running on port 5000

Let's Serve our First Web Page.

Modify your app.py file like so:

  • That's about it, just visit localhost:5000 on your browser
  • And bask in the glory of your simple yet powerful creation.

Next Blog: How to Serve HTML Pages using Flask

Thank the author. Fork this blog.


Tagged in flask