Where to write java script for html page in template directory

I have created a template in templates directory the name of the file is program.html

i have button in that file

<button id="download">Download pdf</button>

now i want to send a ajax request to my program.py file which is located at


what will be the path

in the below script

<script type="text/javascript">

   var xhr = new XMLHttpRequest();
	xhr.open("POST", '/api/method/frappe.utils.print_format.hi');
	xhr.setRequestHeader("X-Frappe-CSRF-Token", frappe.csrf_token);
	xhr.responseType = "arraybuffer";
	xhr.onload = function(success) {
	    if (this.status === 200) {
	        var blob = new Blob([success.currentTarget.response], {type: "application/pdf"});
	        var objectUrl = URL.createObjectURL(blob);

	        //Open report in a new window


please help

You can put your .js file under templates/includes directory and include it in your html with

{% include “your_app_name/templates/includes/program.js” %} and call .py from there

1 Like


thanks very much

and can you help me with the path also

xhr.open(“POST”, ‘/api/method/frappe.utils.print_format.hi’);

Refer to this for an example


oh man thats what i wanted i have been searching for 3 days thanks a lot