This Is A Python Flask Web Application That Allows Users To Shorten Urls
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:
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 original_url field stores the original url provided by the user.
4.Flak Routes
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 .
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
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.