Step 1:Installing the dependencies
* pip install flask
* pip install pyshorteners
Step2: Importing the libraries
from flask import Flask,request,render_template
import pyshorteners
Step3: Declare a constructor
app=Flask(__name__)
Step4: Create your webpage & Write the logic
@app.route('/')
def home():
if request.method == 'GET':
url=request.args['name']
s=pyshorteners.Shortener()
shorter=s.tinyurl.short(url)
return shorter
return render_template('home.html')
Step 5: Run the app
if __name__=='__main__':
app.run(debug=True)
Step6: Home.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>URL SHORTNER</title>
</head>
<body>
<h1>*UNDERATED URL SHORTNER*</h1>
<form action="/" method="GET">
<input type="text" name="name" placeholder="Enter the URL">
<input type="submit">
</form>
</body>
For full understanding of code Must watch the video type of content:
Where is home.html file
ReplyDeleteI will Update in few min..!
ReplyDelete