jquery - Django - Returning a JSON response that has HTML code inside of it -


i trying return json response in django called ajax. json response list each index containing sort of html code. running errors when try parse response in jquery after have pulled ajax. chrome developer tools tell me error when try log received json response in console uncaught syntaxerror: unexpected token &

here code use return json response django contains html code inside of it.

template = loader.get_template('home_post.html') post_arr = [] post in posts:     context = context({'image': post.image, 'body': post.body})     post_arr.append(escape(template.render(context))) return httpresponse(json.dumps(post_arr), content_type='application/json') 

is there way should doing other doing right now? in, there built in way escape html code can put in json response?

yes, use built-in safe template filter.

documentation.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -