0
遍布全球的人们使用Php脚本在AngularJS和Mysql数据库之间进行查询。我正在制作一个Flask应用程序,并希望使用Python进行查询,但我不知道如何。谁能帮我? 这是我试过到目前为止: Python脚本:如何编写一个python脚本来连接AngularJS和mysql数据库?
import pymysql
connection = pymysql.connect(host='localhost',
user='root',
password='*******',
db='testdb',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
cursor = connection.cursor()
cursor.execute("SELECT * from posts")
posts = cursor.fetchall()
记者:从您pyscript
var application = angular.module("myApp", []);
application.config(['$interpolateProvider', function($interpolateProvider) {
$interpolateProvider.startSymbol('[{');
$interpolateProvider.endSymbol('}]');
}]);
application.controller("postController", function($scope, $https){
$https.get("dbconnect.py").then(function(response) {
$scope.posts = response.data.records;
});
});
很难知道你问这里。您正在使用Flask,因此您应该编写一个接受Ajax请求并查询数据库的Flask路由处理程序。 –
@DanielRoseman我期待着这样的事情。 。 。 https://www.w3schools.com/angular/angular_sql.asp –
我不明白什么链接与任何事情有关。正如你所说,你正在使用Flask。你大概已经知道如何编写一个Flask视图来查询数据库并将结果返回给模板。为什么要用Ajax做到这一点有什么不同? –