Apache, Python and mod_wsgi

Asked

Viewed 101 times

0

Sirs, I use simple web applications, running in 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 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 like:

 <?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 code. Usually the return is in JSON.

I’m learning Python and although I love PHP, scripts like this are much simpler to write in Python, which made me look for a way to port my requests.

I don’t want to use frameworks, like Django, as my goal is not to serve 100% Python applications. I just need to send an ajax request, let Python collect the information I asked for and return to JS a JSON for the browser to do the rest.

I’ve tried cgi, I’m getting a lot of wsgi, but I can’t do it.

Would anyone have any light on how to use Python that way? I want to continue serving html pages and use ajax for server-side scripts. It is possible?

From now on, thank you.

  • Linux server?

  • In fact, on a development station. Mac at home and Windows at work. deploy will be on a Windows server with Windows Server 2008.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.