0% found this document useful (0 votes)
17 views

This Is A Python Flask Web Application That Allows Users To Shorten Urls

This summarizes a Python Flask web application that allows users to shorten URLs. It uses SQLAlchemy to connect to an SQLite database. The application defines a URL model with fields for the original URL, shortened URL, and ID. It includes routes for the home page, shortening URLs, displaying shortened URLs, and deleting URLs. The front-end contains templates for the layout, URL submission form, and display of shortened URLs.

Uploaded by

Padhu Devalla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

This Is A Python Flask Web Application That Allows Users To Shorten Urls

This summarizes a Python Flask web application that allows users to shorten URLs. It uses SQLAlchemy to connect to an SQLite database. The application defines a URL model with fields for the original URL, shortened URL, and ID. It includes routes for the home page, shortening URLs, displaying shortened URLs, and deleting URLs. The front-end contains templates for the layout, URL submission form, and display of shortened URLs.

Uploaded by

Padhu Devalla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

This is a Python Flask web application that allows users to shorten urls.

It
uses SQLAlchemy as an Object Relational Mapping tool for working with the
SQLite database .Here is a complete explanation of the code.

1.Required libraries:

First,the required python libraries are imported.

2.Flask Application setup:

*Then ,the flask application is initialized and sqlalcjemy is configured to use a


SQLite database .

*The Migrate object is also initialized to handle database migrations.

3.URL Model:

*The URL class is defined as a model for the database table “shorten _url”.It
has three feilds,id,original_url,short_url.

*The id field is an integer primary key that auto increments .

*The original_url field stores the original url provided by the user.

*The short_url field stores the shortened URL generated .

4.Flak Routes

The @app.route decorator is used to define the Flask application endpoints.

There are four flask routes defined in this application

Home Page:

The home page rote just renders the shorten.html template ,which contains a
form for submitting URL to be shortened.

Shorten_url():

This function handles the form submission by getting the adding the original
URL from the form data,generating the short_url using Pyshorteners
library,and adding original url and short url to the database .

If the original Url already exists in the database,the function returns a


message indicating that the Url has already exists.
Display():

Display() retrieves all distinctive URLs from the database and renders them in
the display.html template.

Delete():

Delete() function deletes the url with specifies id from the database

5.Front_end

The front endv of the Url shortener contains three templates.

Layout.hrml:

The layout.html file defines the basic structure of the website using html and
css.

The navigation bar is also included in this file .The navigation bar indicates
links to the home page and history page.

Shorten.html:

The shorten.html file includes the form submitting the UrL to be shortened
the form has a single input field for the Url,and submit button that sends
form data to the server for processing .

The HTML code also includes a script for copying the shortened URL to the
clipboard

Display.html:

This file includes displays all the distinctive URLs shortened by the
application.The HTML code uses a forloop to iterae through the list of URLs
and display them in the table.The table also has delete button to delete each
entry.

You might also like