Create Text to HTML converter using Django template

Have you ever wondered to write just simple text in a text editor and got a html code for it something similar to text to html converter. It would be amazing that you can write an HTML code without actually writing it. Being a part of the technical field we have to learn a programming language, its syntax, its function and so on, which is not enough in this competitive era where learning one programming language is not enough. So it would be awesome to lighten the burden of at least one language where you don’t need to learn programming language and get a code for it. Yes you are getting it correct, we are talking about text to html converters.

Text-to-Html converter

In this blog, we are going to create a text to html converter using a django template, it is going to be really cool. We are going to use django for the template and text editor, and javascript for converting the text.

Let’s learn how to create your very own text to html converter.

Text to HTML convertor using Python Django

Step 1. Create Django Project

The first step is to create a django project folder, an app folder in that folder and install django-ckeditor.

  1. Create a Django project.
django admin startproject blog_text_to_html
  1. Create app in that django-project.
python startapp texteditor
  1. Install django-ckeditor, ckeditor provides a text editor in django.
pip install ckeditor

4. Add your app name in installed apps.


Step 2. Add files and Folder to the Django Project

We need to create a template folder in the django folder and a file in the app folder.

  1. Create a new folder in the django folder(here, blog_text_to_html folder) save it with the name template.
  2. Add the path for this template folder in blog_text_to_html > .

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

3. Create a new file in the app folder(here, text editor) save it with the name .

4. Add path for this file in blog_text_to_html > .

from django.contrib import admin
from django.urls import path,include
urlpatterns = [

Step3. Create Text to Html convertor

For creating text to html converters we have to create a class model named Editor in which we are going to have our text editor template. After the model we need to create a form of that model.
1. Create a model for Editor in texteditor(your_app_name) > .

from django.db import models
from ckeditor.fields import RichTextField
class Editor(models.Model):

2. Create a form for the model in texteditor > .

from django import forms
from .models import Editor
from ckeditor.widgets import CKEditorWidget
class EditorForm(forms.ModelForm):
    body = forms.CharField(widget=CKEditorWidget(),label="Text Editor")
    class Meta:

3. Create html file in template>index.html .


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Text to html editor</title>
   <!-- ++++++++++++++++++++ boostrap cdn ++++++++++++++++++++++++ -->
    <link rel="stylesheet" href=""
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    #cke_id_body {
        width: inherit !important;
    .htmleditor p {
        font-weight: 900;
        font-size: 20px;
    .texteditor p label {
        font-weight: 800;
        font-size: 18px;
    #htmldata {
        font-weight: 600;
    <!-- ----------------------Navbar start -------------------- -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <a class="navbar-brand" href="#">Text to Html Convertor</a>
    <!-- ---------------------------Navbar Ends---------------------------- -->
  <div class="container-fluid">
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-6 col-6">
                <div class="texteditor">
                <input type="submit" class="btn btn-info" onclick="TextConvert()">
            <div class="col-lg-6 col-md-6 col-sm-6 col-6">
                <div class="htmleditor">
                    <p>HTML Editor</p>
                    <div class="form-group">
                        <textarea class="form-control " rows="16" id='htmldata'>
    function TextConvert() {
        var x = CKEDITOR.instances['id_body'].getData();
        var y = document.getElementById('htmldata');
        y.innerHTML = x;
<!-- ++++++++++++++++++++ boostrap cdn ++++++++++++++++++++++++ -->
<script src=""
<script src=""
<script src=""

4. Create a path for the index html page in texteditor > .

from django.urls import path,include
from . import views
urlpatterns = [

5. Create a function for the index page in texteditor > .

from django.shortcuts import render
from .models import Editor
from .forms import EditorForm
def index(request):
    return render(request,'index.html',{'form':form})

Output :-

Text-to-Html-convertor output

Quick Revision

  1. Create your django project folder.
  2. Create an app folder in the django project folder.
  3. Install django-ckeditor.
  4. Add template folder in the django folder and provide its path in django_folder > .
  5.  Add file named as in the app folder and provide its path in django_project >
  6. Create a model for Editor class in app_folder >
  7. Create a form for the model in app_folder >
  8. Write html code for the converter in django_project > template > index.html.
  9. Add path of index html page in app_folder >
  10. Create function for the index html page in app_folder >

GitHub link :-