Python Flask Project: Website Connectivity Checker

Posted by

Flask Project: Site Connectivity Checker in Python

Flask Project: Site Connectivity Checker in Python

Flask is a micro web framework for Python that allows you to easily create web applications. In this project, we will be creating a site connectivity checker using Flask and Python.

Overview

In this project, we will create a simple web application that allows users to enter a website URL and check if the site is reachable. We will use the requests library in Python to make a HTTP request to the given URL and display the status code of the response.

Installation

Before starting the project, make sure you have Flask and requests library installed. You can install them using pip:

        
            $ pip install Flask
            $ pip install requests
        
    

Creating the Flask Application

Now, let’s create a Flask application that will serve as our site connectivity checker:

        
            from flask import Flask, request
            import requests

            app = Flask(__name__)

            @app.route('/')
            def home():
                return 'Welcome to the Site Connectivity Checker!'

            @app.route('/check', methods=['POST'])
            def check_site():
                url = request.form['url']
                try:
                    response = requests.get(url)
                    return f'The status code of {url} is {response.status_code}'
                except requests.exceptions.RequestException as e:
                    return f'Error connecting to {url}: {e}'

            if __name__ == '__main__':
                app.run()
        
    

Running the Application

Save the above code in a file named app.py and run the Flask application:

        
            $ python app.py
        
    

Visit http://127.0.0.1:5000/ in your browser to access the site connectivity checker. Enter a URL in the input field and click the ‘Check Site’ button to see the status code of the website.

Congratulations! You have successfully created a site connectivity checker using Flask and Python.

0 0 votes
Article Rating
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@John-xi2im
7 months ago

very awesome explanation and epic ideas for python programmers! thanks a lot @neuralnine

@elgeempire493
7 months ago

Thx go continue video agmfter all this years
Great job continue

@pascalpicavez4243
7 months ago

Very interesting video

@rangabharath4253
7 months ago

Awesome as always 🎉🥳