html:
<script type="text/javascript" src="static/js/main.js"></script><script>
function AjaxTest(){
$.ajax({
url:"/test_sql",
type:'POST',
data:{host:$('#IPhost').val(),user:$('#username').val(),passwd:$('#passwd').val(),dbname:$('#dbname').val()},
success: function (arg) {
alert(arg["massage"]);
}
});
}
</script>
views:
from django.http import JsonResponse
def test_sql(request):
host=request.POST.get("host")
user=request.POST.get("user")
passwd=request.POST.get("passwd")
dbname=request.POST.get("dbname")
result=test_connect(host, user, passwd, dbname)
massage=JsonResponse({"massage":result})
return massage