Coders Packet

URL Shortener Using Python

By Nitish Kumar Singh

This project is a web service that takes a long URL and generates a short URL, which is shorter in length. The purpose of the project is to make long URLs more manageable and easier to share.

A URL shortener is a web service or application that takes a long URL and generates a shortened version, which is typically much shorter in length. The purpose of a URL shortener is to make long and cumbersome URLs more manageable and easier to share, especially on platforms with character limits like social media.

--> Detail About the code:-

1. Importing necessary modules:

  • random and string modules are used to generate random characters for the short URLs.
  • Flask is the web framework we'll use for building the web application.
  • request is used to access incoming request data.
  • redirect is used to redirect users to the original URL.
  • render_template is used to render HTML templates.

2. Creating the Flask Application

3. URL mapping dictionary.

4.Generating the short URL.

The function generate_short_url() generates a random short URL of length 6. It uses the random.choice() function to pick characters randomly from the set of letters (both upper and lower case) and digits. The short_url is a string created by concatenating these random characters.

5.Creating the Routes

    a. Shorten URL Route

    b. Redirect to Original URL route

6. Running the application.

 

---> Brief description of the above description part of the code:-

To Complete this project in Python I used Flask Web Framework.

This code sets up a basic Flask application with two routes: one for shortening URLs and another for redirecting users to the original URL. The generate_short_code function generates a random 6-character alphanumeric code for each URL.

 

Then I created an HTML file that will give a user interface. There will be an input section where you need to give the long URL and after submitting the user will get the Small URL.

 

OUTPUTS:-

Output1

output2

output3

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Nitish Kumar Singh (Nitish0909)

Download packets of source code on Coders Packet