Commit 820b0118 by Calen Pennington

Merge pull request #7155 from edx/django-upgrade/unicode-csrf-tokens

Teach edx-mako to force csrf_tokens to unicode (from smart_strings)
parents 0c1cc07b cbcb0ee8
......@@ -122,6 +122,13 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'):
context_dictionary.update(item)
if context:
context_dictionary.update(context)
# "Fix" CSRF token by evaluating the lazy object
KEY_CSRF_TOKENS = ('csrf_token', 'csrf')
for key in KEY_CSRF_TOKENS:
if key in context_dictionary:
context_dictionary[key] = unicode(context_dictionary[key])
# fetch and render template
template = lookup_template(namespace, template_name)
return template.render_unicode(**context_dictionary)
......
......@@ -975,7 +975,7 @@ def xblock_view(request, course_id, usage_id, view_name):
return JsonResponse({
'html': fragment.content,
'resources': hashed_resources.items(),
'csrf_token': str(csrf(request)['csrf_token']),
'csrf_token': unicode(csrf(request)['csrf_token']),
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment