'Can not get textfield value fetched from MySQL in javascript

I created a model in django like below.

class MyDB(models.Model):
    pub_date = models.DateTimeField(_("Date added"),editable=True, auto_now_add=False)
    title = models.CharField(max_length=256,blank=True,null=True)
    text = models.TextField(_("Text"))

Then I got the model and mapped into Frontend.

in views.py file

context['mydb'] = MyDB.objects.all()

in HTML file

let plots = [];
{% for d in mydb %}
    var id = '{{ d.id }}';
    var title = '{{ d.title }}';
    var text = '{{ d.text }}';        
    console.log(text)
        
{% endfor %}

When the text contains 'enter' in string. it raise error.

enter image description here



Solution 1:[1]

Please try to replace ' with ` (backtick), it should fix your issue (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#multi-line_strings)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 benmotyka