Bird
0
0

Which code snippet correctly initializes CSRF protection in a Flask app using Flask-WTF?

easy📝 Syntax Q3 of 15
Flask - Security Best Practices
Which code snippet correctly initializes CSRF protection in a Flask app using Flask-WTF?
Acsrf = CSRFProtect() csrf.init_app(app)
Bcsrf = CSRFProtect()
Ccsrf = CSRFProtect(app) csrf.disable()
Dcsrf = CSRFProtect() app.csrf = csrf
Step-by-Step Solution
Solution:
  1. Step 1: Understand CSRFProtect initialization

    CSRFProtect can be created without app, then linked with init_app.
  2. Step 2: Identify correct pattern

    Creating csrf without app and calling init_app(app) is correct.
  3. Final Answer:

    csrf = CSRFProtect() followed by csrf.init_app(app) -> Option A
  4. Quick Check:

    CSRF init pattern = create then init_app [OK]
Quick Trick: Create CSRFProtect then call init_app(app) [OK]
Common Mistakes:
MISTAKES
  • Passing app directly and then disabling CSRF
  • Assigning csrf to app attribute without init_app
  • Not calling init_app when created without app

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes