Bird
0
0

Which Django template filter should you use to safely display HTML content stored in a variable?

easy📝 Conceptual Q2 of 15
Django - Security Best Practices
Which Django template filter should you use to safely display HTML content stored in a variable?
Asafe
Bescape
Cstrip_tags
Durlencode
Step-by-Step Solution
Solution:
  1. Step 1: Identify the filter that marks content as safe

    The 'safe' filter tells Django not to escape the variable and trust its HTML content.
  2. Step 2: Understand the purpose of other filters

    'escape' escapes HTML, 'strip_tags' removes HTML tags, and 'urlencode' encodes URLs, so they don't fit the need.
  3. Final Answer:

    Use the 'safe' filter to display trusted HTML content. -> Option A
  4. Quick Check:

    Display trusted HTML = A [OK]
Quick Trick: Use 'safe' filter to show trusted HTML without escaping [OK]
Common Mistakes:
MISTAKES
  • Using 'escape' which escapes HTML instead of allowing it
  • Confusing 'strip_tags' with safe display
  • Applying 'urlencode' for HTML content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes