Get your own website
template.html
views.py
 
<!DOCTYPE html>
<html>
<body>

<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 views.py you can see what the var1 variable looks like.</p>

</body>
</html>                  
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))                    
127.0.0.1:8000/testing