1

レンダリングされた 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 を使用してブラウザーに追加するとテキストとしてレンダリングされます。

手伝って頂けますか ?

ありがとう

4

0 に答える 0