Multiple LDAP authentication in Django

Django allows multiple LDAP configuration. The example of the configuration is given here:

To do this we need to create a Python module under site-packages. For example we can create a module called ‘mypackage’.

$ ls /home/administrator/websenv/lib/python2.7/site-packages/mypackage

We can leave empty, and write the following entry into
from django_auth_ldap.backend import LDAPBackend

class LDAPBackend1(LDAPBackend):

class LDAPBackend2(LDAPBackend):

class LDAPBackend3(LDAPBackend):

Now, we can configure the ldap in Django This is an example of a configuration in Django.

import ldap
from django_auth_ldap.config import LDAPSearch


AUTH_LDAP_2_SERVER_URI = "ldap://"
AUTH_LDAP_3_SERVER_URI = "ldap://"
AUTH_LDAP_1_SERVER_URI = "ldap://"



In the example above, we created three backends LDAP1, 2, and 3. We first import the backends to Django and set the URI, DN_TEMPLATE, and bind the domain.

We may need to restart Django and the server:

$python syncdb
$sudo apachectl restart

Fixing Django admin style

I was trying out django tutorial. It works fine when I use the webserver provided by django. But when I tried to deploy on an Apache server. The admin page has lost its style. I tried to google around, and show suggestion to set Apache Alias for media to redirect to the media folder for django. But I couldn’t find media folder for django. It turns out that from django 1.4 onwards we should refer to static folder instead. So this is the modification that I made:

On /etc/apache2/apache2.conf:


Alias /static/admin /home/ubuntu/websenv/lib/python2.7/site-packages/django/contrib/admin/static/admin/


to point to the location of the static files for admin page. And that solves my problem.