To add live chat to Django, you paste the Talkmio install snippet into the base template that every page extends, just before the closing </body> tag, and keep it out of local development with a small condition. That is the whole integration, and it takes about ten minutes. The details worth getting right are where the template lives, how to switch the chat off in development, how to keep the site key in settings instead of in HTML, and what to do when a content security policy blocks the script.
Talkmio is an AI live chat. Its assistant, Mio, reads your public pages and any documents you upload, answers visitors in their own language and hands the conversation to your team when a person is needed. A Django site, whether it is a company site, a shop or a web application with a public marketing section, is a good fit because most of the answers already exist in templates and documentation.
What You Need Before You Add Live Chat to Django
You need three things: a Django project you can deploy, a free account at app.talkmio.com, and a site key. In Talkmio, open Websites, choose Add and enter your domain. Talkmio then shows the site key and the install snippet. This guide uses a placeholder instead of printing the snippet, so you always paste the current version from your own account.
It also helps to know how your templates are organised. Django builds pages from templates that extend one another, and the Django template language reference explains the inheritance model: a base template defines blocks, and child templates fill them. If every page extends one base template, you edit one file and the chat appears everywhere.
Paste the Snippet into Your Base Template
Open the template that wraps your pages, usually called base.html and stored in a templates directory at the project or app level. Find the closing body tag and paste the snippet above it. A simplified template looks like this:
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{% block title %}My site{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
<!-- Paste the Talkmio snippet from Websites → your site here -->
</body>
</html>
Save the file and reload any page. The chat bubble should appear in the corner. If some pages use a different base template, for example one for the admin-style dashboard and one for the public site, paste the snippet only into the public one. A logged-in application screen rarely needs a sales chat, although a support chat inside an app can be valuable if you want customers to reach your team from there.
Keep Chat Out of Development and Staging
A chat widget on your laptop is noise: you will open conversations from your own test visits and, worse, teach yourself to ignore the bubble. Django gives you two clean ways to keep the snippet out of development. The first is to wrap it in a condition on a context value that you set from settings. The second is to put the snippet in its own partial template and include it only when a setting is on.
| Approach | How it works | Best for |
|---|---|---|
Condition on debug |
Wrap the snippet in {% if not debug %} using the debug context processor |
Small sites with one environment flag |
| Custom setting | Add TALKMIO_ENABLED to settings and expose it through a context processor |
Staging that should stay quiet while production is live |
| Partial template | Move the snippet to partials/chat.html and include it conditionally |
Teams that want one file to edit |
| Separate settings per environment | Set the flag in production settings only | Projects that already split settings files |
Whichever you choose, remember that the debug template variable only appears when the debug context processor is installed and the request comes from an address listed in INTERNAL_IPS. A custom setting exposed through your own context processor is more predictable, and it is the version most teams end up using. The Django settings reference lists the built-in settings you can combine with it.
Store the Site Key in Settings
Hard-coding the site key in a template works, but it ties the template to one environment. If you run a staging site with its own Talkmio website entry, you want a different key there. Read the key from an environment variable in settings, expose it through a context processor, and use the variable inside the partial template where the snippet needs it. Then the template contains no environment-specific values and the same code deploys everywhere.
The site key is not a secret in the way a password is, because it appears in the page source for every visitor. It still belongs in configuration rather than in a template, so a change of key is a deployment setting and not a code change. Talkmio keeps each website separate, and the Free plan includes one website, while paid plans include more. The pricing page lists the limits for each plan.
Static Files, Caching and the Snippet
The Talkmio snippet loads its script from Talkmio, so you do not add anything to your static files and you do not run collectstatic for it. That is a useful property: you never need to update a vendored copy, and a new release of the widget reaches your site without a deployment. If you want to know how Django serves your own assets, the static files how-to is the right reference, but it does not change the chat setup.
Caching deserves one check. If you use a full-page cache, such as a reverse proxy or Django’s per-site cache, the snippet is cached together with the page. That is fine, because it is the same for every visitor. It only becomes a problem if you wrap the snippet in a condition that depends on the user, for example showing it to anonymous visitors only, and cache the result for everyone. Keep the condition based on the environment, not on the visitor, or vary the cache correctly.
If a Content Security Policy Blocks the Chat
Many Django projects set a content security policy through a middleware package or a proxy. A strict policy blocks scripts from unknown hosts, so the chat bubble does not appear and the browser console shows a violation message. The fix is to allow the host the snippet loads its script from, which you can read from the snippet itself. Start with a report-only policy, load a page, read the reports and allow only what is reported. Our guide to chat widget cookies and consent covers the related question of what the widget may load before a visitor agrees.
If you add nonces to your inline scripts, remember that the snippet must carry the same nonce as your other scripts. Django does not add nonces by itself, so the way to do this depends on the package you use. Test in a production-like environment, because a policy that is relaxed in development hides the problem until launch day.
Teach Mio Your Django Site
With the widget visible, spend your time on the knowledge. In Talkmio, open Mio AI and then Knowledge base, add your website, and Mio reads every public page on the same domain while respecting robots.txt. Add the documents that do not live on a page, such as a PDF price list or terms of service. Talkmio accepts PDF, DOCX, TXT, MD, CSV and HTML files up to 15 MB. Then write business instructions that state what Mio must not promise, for example never to quote a delivery date.
Test it in the same session. Use Try Mio to ask the five questions your customers ask most and check which knowledge pieces Mio used. Our article on testing an AI chatbot before launch contains a question list you can adapt. A Django site that renders content from a database may hide pages from the crawler behind logins or filters, so check that the important pages are public and linked.
Django Sites in Several Languages
Django has strong support for translated sites, with language prefixes in URLs and translated templates. Chat needs very little extra work, because Mio replies in the language the visitor writes in, and a question in one language can find an answer written in another. In the widget settings for your website you choose whether the chat window auto-detects the language or uses a fixed one. A site with per-language URLs usually works best with auto-detect, so the window follows the visitor.
The knowledge base is where multilingual sites need care. If your English and German pages say different things, for example different delivery areas, Mio may quote the wrong one. Keep the facts consistent across languages, and when you add live chat to Django sites that serve different countries, state in the business instructions which rules apply to which market. Our guide to multilingual live chat goes deeper on this.
Troubleshooting Checklist
When the bubble does not appear, work through four checks in order. Is the snippet in the template that the page actually extends? Is the condition true in the environment you are testing? Does the page source in the browser show the script tag? Does the console report a blocked request from a content security policy or an ad blocker? Fixing the first one that fails solves most cases. If all four look right, test in a private window with extensions disabled, because privacy extensions block many third-party scripts.
If you manage several Django sites, repeat the setup per site with its own site key, and keep one shared partial template in your project template so the pattern stays identical. The general version of this checklist is in our guide on how to add live chat to a website, and the integrations page lists the platforms with ready-made plugins.
Frequently Asked Questions
Where in a Django project does the chat snippet go?
Paste it into the base template that your pages extend, just above the closing body tag. Because every child template inherits from it, one edit puts the chat on every page. If you have a separate base template for private application screens, leave the snippet out of that one.
Do I need to install a Python package for Talkmio?
No. The integration is a script snippet in a template, so there is nothing to install with pip and nothing to add to your static files. The script loads from Talkmio, and new widget releases reach your site without a deployment on your side.
How do I hide the chat in local development?
Wrap the snippet in a condition that depends on a setting, for example a custom flag exposed through a context processor, and turn it on only in production. The debug template variable also works, but it needs the debug context processor and a listed internal address.
Why does the chat bubble not show on my Django site?
The usual causes are a snippet in the wrong template, a condition that is false in that environment, a content security policy that blocks the script host, or a browser extension that blocks third-party scripts. Check the page source and the browser console, in that order.
Can I use a different site key for staging?
Yes. Add a second website in Talkmio for staging, read each key from an environment variable in settings and expose it to the template. The Free plan includes one website, and paid plans include more, so check the pricing page for the limit on your plan.
Is the free plan enough to test live chat on Django?
Yes. The Free plan includes one operator, one website and 50 AI answers a month, which is enough to install the chat, teach Mio your content and try it on real questions before you decide whether to upgrade.
The Bottom Line
To add live chat to Django, paste one snippet into the base template, switch it off in development with a setting and keep the site key in configuration. Then put your effort into the knowledge base and the instructions, because that is what decides whether visitors get good answers. Start free with Talkmio, add your website and ask Mio your three most common questions before you tell anyone the chat is live.
