DEV Community

Cover image for ☁From Code to Cloud: A Step-by-Step Guide to Building and Deploying Python Flask Applications πŸ‘¨πŸ½β€πŸ’»
BAKRE JAMIU
BAKRE JAMIU

Posted on

☁From Code to Cloud: A Step-by-Step Guide to Building and Deploying Python Flask Applications πŸ‘¨πŸ½β€πŸ’»

☁ Cloud-Based Development: A Beginner's Guide to Building Python Flask Applications with Deployment.☁

Getting Started πŸ‘¨πŸ½β€πŸ’»

To begin, ensure you have a Linux environment set up. If you're using Windows 10, install Windows Subsystem for Linux (WSL) and configure an instance, as outlined in my previous article.

File Extensions Overview

Familiarize yourself with common file extensions:

πŸ”΅ Python: .py
πŸ”΅ JavaScript: .js
πŸ”΅ C#: .cs
πŸ”΅ Ruby: .rb
πŸ”΅ PHP: .php

Our Focus

In this tutorial, we'll concentrate on building and deploying Python application, utilizing .py

Deployment Guide: Python Application.

Section A

Create an Instance

Follow the detailed instructions in my previous article to create an instance on AWS EC2: Post

Refer to Section A for the step-by-step guide πŸ€“.

Section B

Connect to Your Server 🀭

Once your instance is set up, connect to your server by following Section B in the same article: Post

Stay Tuned 😯

For the pictorial deployment guide of Python application.

Section C

Deployment Phase

Step: Update Virtual Server😌😊.

Image description

Step 2: Verify Python Installation - Check Version.

Image description

Step 3: Create 'apps' Directory and Verify.

Image description

Step 4: Access 'apps' Folder, Create a New File and Open for Editing.

Image description

Step 5: Add Your Code to the Newly Created File

Image description

Step 6: Save & Exit Nano Editor (Ctrl x, Y, Enter)

Image description

Step 7: Review File Contents.

Image description

Step 8: Execute Python Code.

Image description

Step 9: Set Up Virtual Environment.
(1. You can see it’s not install) (2. You can see it is not install) (3. Install virtual environment {venv})

Check if Virtual Environment is Installed.

python3 -m venv
Enter fullscreen mode Exit fullscreen mode

If not installed:

sudo apt-get install python3-venv
Enter fullscreen mode Exit fullscreen mode

Image description

Step 10: Run and Activate venv

To activate:

Source Jamiu/bin/activate
Enter fullscreen mode Exit fullscreen mode

Image description

Step 11: Install Flask framework Using pip.

pip install flask
Enter fullscreen mode Exit fullscreen mode

Image description

Step 12: List packages installed in the virtual environment.

Image description

Step 13: Create app.py and Open in Nano Editor.

Insert this code:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, This is my first Live Python Flask app!</p>"
Enter fullscreen mode Exit fullscreen mode

Image description

Step 14: Execute app.py with Python and Start Flask Server.

Image description

Flask app is running, but only accessible internally.

Step 15: Go Live - Make Application Accessible to External Users.

Image description

Step 16: Verify Application Status - Running and Active.

Image description

Congratulations! πŸŽ‰ You've Successfully Deployed Your First Flask Application in Python. πŸ•ΊπŸ½πŸ•ΊπŸ½πŸ•ΊπŸ½

Conclusion:
We've reached the end of this installment. Keep an eye out for my upcoming article, arriving in the next few daysπŸ˜ŠπŸ™‚πŸ˜Œ.

Top comments (0)