Install the django-autocomplete-light
package with pip¶
Install the stable release, preferably in a virtualenv:
pip install django-autocomplete-light
Or the development version:
pip install -e git+https://github.com/yourlabs/django-autocomplete-light#egg=autocomplete_light
Append 'autocomplete_light'
to settings.INSTALLED_APPS
¶
Enable templates and static files by adding autocomplete_light
to
settings.INSTALLED_APPS which is
editable in settings.py
, it can look like this:
INSTALLED_APPS = [
# [...] your list of app packages is here, add this:
'autocomplete_light',
]
Call autocomplete_light.autodiscover()
before admin.autodiscover()
¶
In urls.py
, call autocomplete_light.autodiscover()
before
admin.autodiscover()
, it can look like this:
import autocomplete_light
# import every app/autocomplete_light_registry.py
autocomplete_light.autodiscover()
import admin
admin.autodiscover()
Include autocomplete_light.urls
¶
Install the autocomplete view and staff debug view in urls.py
using the include function,
it can look like this:
# Django 1.5:
from django.conf.urls import patterns, url, include
# In Django 1.4:
# from django.conf.urls.default import patterns, url, include
urlpatterns = patterns('',
# [...] your url patterns are here
url(r'^autocomplete/', include('autocomplete_light.urls')),
)
Ensure understanding of django.contrib.staticfiles
¶
Ensure that you understand django-staticfiles, if you don’t try this article or refer to official howto and topic.
Include autocomplete_light/static.html
after loading jquery.js (>=1.7)¶
Load the javascript scripts after loading jquery.js
, it can look like this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js" type="text/javascript"></script>
{% include 'autocomplete_light/static.html' %}
Optionaly include it in admin/base_site.html
too¶
For admin support, override
admin/base_site.html
. It could look like this:
{% extends "admin/base.html" %}
{% block extrahead %}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js" type="text/javascript"></script>
{% include 'autocomplete_light/static.html' %}
{% endblock %}
Note
There is nothing magic in how the javascript loads. This means that you can use django-compressor or anything.