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 manage.py 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 urls.py 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 > settings.py .


        '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 urls.py .

4. Add path for this url.py file in blog_text_to_html > urls.py .


from django.contrib import admin
from django.urls import path,include
urlpatterns = [
    path('admin/', admin.site.urls),

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) > models.py .


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

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


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="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        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="https://code.jquery.com/jquery-3.3.1.slim.min.js"
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"

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


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

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


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 > settings.py .
  5.  Add file named as urls.py in the app folder and provide its path in django_project > urls.py.
  6. Create a model for Editor class in app_folder > models.py.
  7. Create a form for the model in app_folder > forms.py.
  8. Write html code for the converter in django_project > template > index.html.
  9. Add path of index html page in app_folder > urls.py.
  10. Create function for the index html page in app_folder >views.py.

GitHub link :-