Python 3 Script to Download File as Attachment in Browser Using HTML5 & Javascript Full Tutorial For Beginners

You are currently viewing Python 3 Script to Download File as Attachment in Browser Using HTML5 & Javascript Full Tutorial For Beginners

 

Welcome folks today in this post we will be downloading file as attachment in browser in html5 and javascript. All the source code of the application will be given below.

 

 

 

Get Started

 

 

In order to get started you need to create a text file called input.txt and copy paste the following code

 

input.txt

 

 

 

 

Now just create an app.py file and copy paste the following code

 

app.py

 

 

 

 

Now if you execute app.py by typing the below command

 

python app.py

 

 

 

 

So you can say it is displaying the contents of the text file inside the console. So we want to download this text file instead inside the browser.

 

For this we need to create an index.html file inside the same directory and copy paste the following code

 

 

index.html

 

 

 

 

So now if you open index.html file inside the browser you will see the following output which is shown below

 

 

 

Now if you click the hyerlink then the text file will be downloaded as an attachment as shown below

 

 

Leave a Reply