Bird
0
0

Which of the following is the correct way to mark a variable as safe (not escaped) in a Django template?

easy📝 Syntax Q12 of 15
Django - Security Best Practices
Which of the following is the correct way to mark a variable as safe (not escaped) in a Django template?
A{{ variable|escape }}
B{{ variable|strip }}
C{{ variable|safe }}
D{{ variable|clean }}
Step-by-Step Solution
Solution:
  1. Step 1: Identify the filter that marks content safe

    The safe filter tells Django not to escape the variable, rendering HTML as-is.
  2. Step 2: Check other filters

    escape escapes content, strip and clean are not standard Django filters for safety.
  3. Final Answer:

    {{ variable|safe }} -> Option C
  4. Quick Check:

    Use safe filter to disable escaping = {{ variable|safe }} [OK]
Quick Trick: Use '|safe' to show trusted HTML without escaping [OK]
Common Mistakes:
MISTAKES
  • Using '|escape' which does the opposite
  • Confusing '|strip' or '|clean' as safety filters
  • Forgetting to mark trusted content safe explicitly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes