diff --git a/django/views/debug.py b/django/views/debug.py
index 7c45af230a..3358d2f08e 100644
--- a/django/views/debug.py
+++ b/django/views/debug.py
@@ -422,11 +422,11 @@ TECHNICAL_500_TEMPLATE = """
{% if frame.context_line %}
{% if frame.pre_context %}
-
{% for line in frame.pre_context %}- {{ line }}
{% endfor %}
+
{% for line in frame.pre_context %}- {{ line|escape }}
{% endfor %}
{% endif %}
-
- {{ frame.context_line }} ...
+
- {{ frame.context_line|escape }} ...
{% if frame.post_context %}
-
{% for line in frame.post_context %}- {{ line }}
{% endfor %}
+
{% for line in frame.post_context %}- {{ line|escape }}
{% endfor %}
{% endif %}
{% endif %}
@@ -445,8 +445,8 @@ TECHNICAL_500_TEMPLATE = """