我想将渲染的html模板包含在json对象中。
def updates(request, game_id, from_staff_comment_id):
game = Game.objects.latest()
staff_comments = StaffComment.objects.find_by_game_with(game_id, from_staff_comment_id)
staff_comments_max = 0
if staff_comments:
staff_comments_max = staff_comments[0].id
game_json = {
'home_score': game.home_score,
'guest_score': game.guest_score,
#'staff_comments': serializers.serialize('json', staff_comments, fields=('time', 'unsername', 'comment')),
'staff_comments_html': render_to_string('live_staff_comment.html', {'comments': staff_comments}),
'staff_comments_max': staff_comments_max
}
return HttpResponse(simplejson.dumps(game_json), mimetype='application/json')
render_to_string()
有效,但html会被转义,因此当我使用javascript将其附加到浏览器时,它会呈现为文本。
你能帮助我吗?
由于