简体   繁体   中英

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.

使用XMLHttpRequest( https://en.wikipedia.org/wiki/XMLHttpRequest )调用您的python脚本并将结果放回您的网页。

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM