Skip to main content

Django app to add Typeahead.js based input elements.

Project description

# Typeahead.js for Django

[![Continuous Integration Status](](
[![Coverage Status](](
[![Latest PyPI version](](

Twitter's [typeahead.js ]( integration for Django.


The goal of this package is to seamlessly integrate Typeahead.js with Django and other django libraries.


* Python >= 3.4
* Django >= 2.0
* jquery >= 1.9


pip install django-typeahead

Add `bootstrap_typeahead` to the list of INSTALLED_APPS in your file.

# ...

This installation instruction assumes you have jQuery already present in your page.



from django import forms
from bootstrap_typeahead.widgets import TypeaheadInput

class StateForm(forms.Form):
query = forms.CharField(
'hint': True,
'highlight': True,
'minLength': 1
'name': 'states',
'source': 'substringMatcher(states)',

The `options` and `datasets` argument will be passed to the JavaScript typeahead instance,
and are documented and demonstrated here:

* [Typeahead Docs]( and [Bloodhound Docs](
* [Interactive Demo](

#### template.html

{% load bootstrap4 %}

{# Load CSS and JavaScript #}
{% bootstrap_css %}

{% block extra_css %}
{{ }}
{% endblock %}

<form method="post" role="form">
{{ form|bootstrap }}
{% csrf_token %}
<div class="form-group">
<input type="submit" value="Submit" class="btn btn-primary" />

{% bootstrap_javascript jquery='full' %}

{% block extra_js %}
<script type="text/javascript">
var substringMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substringRegex;

// an array that will be populated with substring matches
matches = [];

// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');

// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {


var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
{{ }}

{% endblock %}

Here we use [django-bootstrap4]( to translate [the basics]( in Typeahead.js [examples page]( but you can create your HTML forms manually.

Bugs and Suggestions

If you have found a bug or if you have a request for additional functionality, please use the issue tracker on GitHub.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-typeahead, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size django-typeahead-1.0.0.tar.gz (8.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page