Search code examples
djangonext.jssummernote

How to escape HTML tags in NextJS


I have Django backend and Nextjs frontend.

When I try to render content = models.TextField() from my Django backend to Nextjs frontend <p>{data.content}</p> , I get following rendered:

<p>first&nbsp;first&nbs</p>

I use django_summernote as the editor. Django has | safe method, that escapes rendering HTML, but I don't know what to use for NextJS. Any help is appreciated


Solution

  • To escape html tags in next js and safely render HTML from API with styles in page. So you have to do that add the following code:

    <div dangerouslySetInnerHTML={{ __html: data.content }}></div>