Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have a static website built using HTML, CSS and Javascript. How do I integrate this with a SQLite3 database accessed with the Python API?

Title question says it all. I was trying to figure out how I could go about integrating the database created by sqlite3 and communicate with it through Python from my website.

If any further information is required about the development environment, please let me know.

like image 655
Louis93 Avatar asked Oct 04 '22 09:10

Louis93


2 Answers

Use XMLHttpRequest (https://en.wikipedia.org/wiki/XMLHttpRequest) to call your python script and put the results back in your webpage.

like image 191
Scruffy Avatar answered Oct 10 '22 14:10

Scruffy


I'm not sure if you are using JQuery at all but you should use AJAX to make calls to the python api.

Jquery Method: http://api.jquery.com/jQuery.ajax/

$.ajax({
 type: "POST", //OR GET
 url: yourapiurl,
 data: datatosend,
 success: success, //Callback when request is successful that contains the SQlite data
 dataType: dataType
});

Javascript Method: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST",yourapiurl,true);
xmlhttp.send();

The responseText attribute of the XMLHttpRequest be populated with the SQlite data from the api

like image 26
tabiodun Avatar answered Oct 10 '22 14:10

tabiodun