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?

StackOverflow https://stackoverflow.com/questions/17953552

  •  04-06-2022
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책 2

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

다른 팁

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

It looks like your needs has changed and you are going into direction where static web site is not sufficient any more. Firstly, I would pick appropriate Python framework for your needs. if static website was sufficient until recently Django can be perfect for you. Next I would suggest describing your DB schema for ORM used in chosen framework. I see no point in querying your DB using SQL until you would have a specific reason. And finally, I would start using static content of your website as templates, replacing places where dynamic data is required. Django internal template language can be easily used that way. If not, Jinja2 also could be good. My advise is base on many assumptions, as your question is quite open and undefined. Anyway, I think it would be the best way to start transition period from static to dynamic.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top