Get your own Django server
<!DOCTYPE html>

<h3>Without escapejs:</h3>
<button onclick="alert('{{ var1 }}')">Click me</button>

<h3>With escapejs:</h3>
<button onclick="alert('{{ var1|escapejs }}')">Click me</button>

<p>Try clicking both buttons. The JavaScript without the escapejs filter will raise an error.

<p>In you can see what the var1 variable looks like.</p>

from django.http import HttpResponse
from django.template import loader

def testing(request):
  template = loader.get_template('template.html')
  context = {
    'var1': 'John\nDoe',
  return HttpResponse(template.render(context, request))