From Terminal to Web: Hosting Your Chatbot with Django😊🎀


🧁 Wait, What is Django?
Okay real talk…
When I first heard "Django", I thought it was:
A Western movie 🎬
A type of mango 🥭
A dance move 💃
But nope — Django is actually a superhero framework in the Python world 🦸♀️🐍
It helps you build websites really fast without starting from scratch every time.
Think of it like this:
🍰 Django = Cake Mix
You don’t have to grow the wheat, grind the flour, and make everything by hand.
Django gives you all the ingredients and tools to bake your web app in minutes!🏰 Django = IKEA for Websites
It gives you ready-to-assemble parts (like models, views, URLs, templates) so you don’t have to saw wood and build everything from scratch.📦 Django = Magic Box
Want a database? It’s built-in.
Want user login? Built-in.
Want admin panel? Already done.
Want to connect your AI bot? EASY.
So yeah — Django is your Python web BFF 💖
🧪 Step 1: Install Django
✅ For Windows/Linux:
pip install django
2️⃣ Create a Django project
django-admin startproject chatbot_project
cd chatbot_project
3️⃣ Create a Django app
python manage.py startapp chatbot
🖤 Step 3: Tell Django about your app
Open the file:
chatbot_project/settings.py
Look for a list called:
INSTALLED_APPS = [
...
]
Add your app name to the list:
pythonCopyEditINSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'chatbot', # 👈 ADD THIS LINE
]
✅ Save the file.
🖤 Step 4: Create your view
Open the file:
chatbot/views.py
Replace everything in it with:
from django.shortcuts import render
from langchain_ollama import OllamaLLM
llm = OllamaLLM(model="tinyLlama")
def chat(request):
response = ""
if request.method == "POST":
question = request.POST.get("question", "").strip()
if question:
response = llm.invoke(question)
return render(request, "chatbot/chat.html", {"response": response})
✅ Save the file.
📄 What is views.py
in Django?
✅ In Django, a view is just a Python function (or class) that:
🎯 receives a request from the browser
🎯 processes it
🎯 gives back a response (usually an HTML page)
You can think of it as the brain of your page.
🌸 In short:
📥 The view takes input from the user (question)
🧠 Processes it (calls OllamaLLM)
📤 Sends output to the user (response text)
That’s the main job of the view:
🎯 receive → process → respond.
🖤 Step 6: Connect app URLs to project
Open the file:
chatbot_project/urls.py
Replace it with this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('chatbot.urls')), # this is correct
]
✅ Save.
🖤 Step 6: Connect app URLs to project
create the file:
chatbot/urls.py
Replace it with this:
from django.contrib import admin
from django.urls import path, include
from .views import chat
urlpatterns = [
path('admin/', admin.site.urls),
path('', chat, name='chat'), # this is correct
]
✅ Save.
📄 What is urls.py
in Django?
In Django, urls.py
is like a map 🗺️
It tells Django:
“When the user visits this URL in the browser, run this view.”
Without urls.py
, Django wouldn’t know which Python function (view) to call for a given page.
🖤 Step 7: Create the HTML page
In your app folder, create this path:
chatbot/templates/chatbot/chat.html
✅ You may need to create the folders templates
and chatbot
inside it.
Put this inside the file chat.html
:
<!DOCTYPE html>
<html>
<head>
<title>Chatbot</title>
</head>
<body>
<h1>Chat with the Bot</h1>
<form method="post">
{% csrf_token %}
<input type="text" name="question" placeholder="Ask me something" style="width: 300px;">
<button type="submit">Send</button>
</form>
{% if response %}
<h3>Bot says:</h3>
<p>{{ response }}</p>
{% endif %}
</body>
</html>
✅ Save.
🖤 Step 8: Run your app
Run the database setup:
python manage.py migrate
Then run the server:
python manage.py runserver
✅ Open browser and go to:
👉 http://127.0.0.1:8000
You should see a box where you can type a question and click send.
The bot will reply below.
🎀 Sneak Peek for Your Next Blog
🗣️ “Give Your Chatbot a Voice: Building a Web-Based Voice Assistant with Django + LangChain”
Subscribe to my newsletter
Read articles from Sudharshini Jothikumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sudharshini Jothikumar
Sudharshini Jothikumar
I am Sudharshini, a dynamic force in the world of technology and creativity, currently pursuing my MSc in Software Systems. With a passion for problem-solving, I have not only honed my skills but emerged victorious in numerous hackathons, showcasing my prowess in the ever-evolving realm of software development. Beyond the lines of code, I am also a wordsmith, having penned and published two captivating books that reflect my diverse interests. My ability to weave narratives demonstrates a depth of creativity that extends beyond the digital domain. I am also a national-level champion in both Silambam and Adimurai, showcasing my physical prowess and discipline. Whether it's mastering the intricacies of software architecture or gracefully wielding traditional weapons, I embodied a perfect blend of the modern and the traditional. In a world where versatility is key, I stand out as a multifaceted individual, seamlessly navigating the realms of technology, literature, and martial arts with finesse. My journey is not just a narrative of achievements but a testament to the limitless possibilities that arise when one embraces a holistic approach to life.