Last Updated : 23 Jul, 2025
We will build a simple translator app using Django. We will learn how to set up a project, create a form to input text and select a language, and use the Python translate package to convert text from one language to another. Step-by-step, we’ll create a working app that translates user input into different languages.
Install Required PackagesOpen your terminal and run:
Create Django Project and Apppip install django
pip install translate
Refer to the following articles to check how to create a project and an app in Django.
Open terminal and run:
Add App to Installed Appsdjango-admin startproject translator
cd translator
python manage.py startapp main
In translator/settings.py, add "main" to the INSTALLED_APPS list:
Create the ViewIn main/views.py, add the following code:
Python
from django.shortcuts import render,HttpResponse
from translate import Translator
def home(request):
if request.method == "POST":
text = request.POST["translate"]
language = request.POST["language"]
translator= Translator(to_lang=language)
translation = translator.translate(text)
return HttpResponse(translation)
return render(request,"main/index.html")
Create Templates Directory and HTML File
Inside the main app folder, create these directories:
main/
└── templates/
└── main/
└── index.html
Create index.html with the following content:
HTML
<!DOCTYPE html>
<html>
<head>
<title>GFG</title>
</head>
<body>
<form method="post">
{% csrf_token %}
<input type="text" name="translate" required>
<br>
<select required name="language">
<option value="Hindi">Hindi</option>
<option value="Marathi">Marathi</option>
<option value="German">German</option>
</select>
<br>
<button type="submit">Translate</button>
</form>
</body>
</html>
Configure URLs in the App
Create main/urls.py:
Python
from django.urls import path
from .views import *
urlpatterns = [
path('',home,name="home"),
]
Include App URLs in Project URLs
In translator/urls.py, include the app’s URLs:
Python
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include("main.urls"))
]
Run the Development Server
Run the Django server:
python manage.py runserver
Output
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4