Autocomplete in 2026

It looks like it’s been about 5 years since anybody has asked about autocomplete in this forum, and I want to check that I haven’t missed any developments.

I started a new Django project last year, and since I’m using HTMX (for the first time), I installed django-htmx-autocomplete to use for autocomplete fields. But I haven’t been happy with it.

Out of the box, the fields look ugly, and styling them to match the rest of the site required a lot of messy trial and error. And now I want to be able to disable one of the autocomplete fields, with client-side code. I realise the HTMX paradigm is to send the server a request for every little DOM change, but since many of our end users will be connecting to our site on slow or unstable connections, this just isn’t practical. And anyhow, the django-htmx-autocomplete widget doesn’t honour the attr property, and it turns out it’s going to require more CSS fiddling to make disabled fields actually look disabled. So I want to ditch this library.

But the only alternative, it seems, at least without having to include jQuery (which the kids hate these days), is DAL, AKA Django Autocomplete Lite—and it doesn’t seem to be being maintained any more. The docs trumpet about Django 4.2, the last commit was over a year ago, scores of open issues and pull requests are apparently being ignored, and the requirements.txt for the demo contains multiple entries that pip doesn’t know what to do with. (Unfortunately, it also uses the same module name, ‘autocomplete’, in Python, so I guess I’ll have to replace all the autocomplete fields at once, and not be able to leave the existing HTMX-based ones for the time being.)

I could grow my own, but I really don’t want to waste time reinventing the wheel. And I think, surely, I’m missing some other option, since it’s not like autocomplete fields are a new idea. Can the admin autocomplete fields be used for end-user pages somehow? Did I miss a new Django feature that makes these third-party libraries obsolete?

The Django Admin uses the Select2 library for its autocomplete_fields. (See django.contrib.admin.widgets.AutocompleteMixin.) I can’t see any reason offhand why you wouldn’t be able to use that Mixin in your own widgets. (Note, as implemented it’s only usable with FK and M2M fields. It’s not an implementation of a generic autocomplete for unrelated data. However, it might give you some ideas for your own implementation.)

At first glance, Select2 certainly seems stylable and well documented, and if the AutocompleteMixin doesn’t already do exactly what I need, I could probably subclass it. I’ll run with this and let you know how I go. Thanks!

You may also try this implementation:

It is based on Tom-Select and warpped into a web component. It does not require jQuery as Select2 does.

@jrief : TBH, the keyboard issue I mentioned is probably the only thing standing in the way of me seriously giving django-formset a go, because it seems like a ripper otherwise. I’ve added a comment about this, to what seems to be a closely related issue on GitHub. Please let me know whether you agree with my impressions of what keyboard behaviour should be, and if so, when I can expect a release with it implemented this way. I can try to fix it myself and send a pull request, if you like.

Edit: Whoops—it looks like I overwrote my original comment, instead of adding a new one. I originally wrote that I think django-formset might be the thing that I’ve been missing, because it seems to offer standard implementations for widgets that I’ve either written by hand, or used libraries for that I’m not entirely happy with. But apart from the issue that I’ve now explained in that GitHub comment, I also don’t like how users need to open the drop-down to see which options they’ve ticked where multiple selections are possible.

My other question is about styling. I’ve never found a CSS framework I like—all the ones I’ve tried mess up standard CSS (especially Bootstrap, which I spent numerous working weeks fighting with in the 2010s). But from the Styling docs, it looks like I don’t have to use any of them. All my existing forms render as_table, and they look pretty good that way, apart from the django-htmx-autocomplete widget in some cases. (I’ve hacked it into submission for the most part.) Will django-formset work for forms rendered as_table, or will I just have to restyle everything, maybe using one of the CSS frameworks, if there’s one that’s friendly to old hands at CSS.

Thanks!