Bird
0
0

This code snippet throws an error:

medium📝 Debug Q7 of 15
Flask - Ecosystem and Patterns
This code snippet throws an error:
from flask import Flask
from flask_caching import Cache
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
cache.init_app(app)

What is the problem?
AFlask app instance is not created
BCACHE_TYPE 'simple' is invalid
CCache extension is not installed
DCalling init_app after passing app to Cache constructor causes error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze Cache initialization

    Passing app to Cache constructor initializes it immediately; calling init_app again is redundant and causes error.
  2. Step 2: Identify correct usage

    Either pass app in constructor or call init_app later, not both.
  3. Final Answer:

    Calling init_app after passing app to Cache constructor causes error -> Option D
  4. Quick Check:

    Double init causes error = init_app misuse [OK]
Quick Trick: Use either constructor app param or init_app, not both [OK]
Common Mistakes:
MISTAKES
  • Misunderstanding CACHE_TYPE values
  • Forgetting to create Flask app
  • Ignoring extension installation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes