Sirs, I use simple web applications running on Apache2 and with PHP on the server to automate trivial tasks on my work team. I use PHP only for LDAP and BD requests, using jQuery, lodash and pure JS for everything else. I'm migrating many bases to CouchDB, which makes it much easier on the front end.
I usually send the requests to the server with $.ajax
, $.post
and $.get
. For example:
$.post({
url: 'server/teste.php',
success: res => {
console.log(res);
}
});
On the server, I have files of type:
<?php
$conn = ldap_connect("localhost", 10389) or die("Sem conexão\n");
if ($conn)
{
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($conn, LDAP_OPT_REFERRALS, 0);
$bind = ldap_bind($conn, 'uid=admin,ou=system', 'secret') or die ("Bind recusado\n");
if ($bind)
{
$dn = 'ou=usuarios,o=bb,c=br';
$filter = '(uid=*)';
$attr = ['cn', 'sn', 'departmentNumber', 'ou', 'title', 'uid'];
$pesq = ldap_search($conn, $dn, $filter, $attr) or die ("Pesquisa não realizada\n");
if ($pesq)
{
$res = ldap_get_entries($conn, $pesq);
}
}
ldap_close($conn);
}
print_r($res);
This is just an example of the code. Usually the return is in JSON.
I'm learning Python and although I love PHP, scripts like this are a lot simpler to write in Python, which made me look for a way to port my requests.
I do not want to use frameworks, like Django, since my goal is not to serve 100% Python applications. I just need to send an ajax request, let Python collect the information I requested and return it to JS a JSON for the browser to do the rest.
I've tried cgi, I'm picking up a lot of wsgi, but I can not do that.
Would anyone have any light on how to use Python in this way? I want to continue serving the pages in html and use ajax for the server side scripts. Is it possible?
Thanks in advance.