Bird
0
0

What is the main issue in this Flask code that breaks the pattern and causes an error?

medium📝 Debug Q14 of 15
Flask - Ecosystem and Patterns
What is the main issue in this Flask code that breaks the pattern and causes an error?
from flask import Flask, Blueprint

bp = Blueprint('bp', __name__)

@bp.route('/test')
def test():
    return 'Test page'

app = Flask(__name__)

if __name__ == '__main__':
    app.run()
ABlueprint is not registered with the Flask app
BRoute decorator syntax is incorrect
CFunction test() is missing a return statement
DFlask app is not created properly
Step-by-Step Solution
Solution:
  1. Step 1: Check Blueprint usage

    The Blueprint 'bp' is defined with a route but never registered to the app.
  2. Step 2: Understand effect of missing registration

    Without registering, Flask does not know about the Blueprint routes, causing 404 errors.
  3. Final Answer:

    Blueprint is not registered with the Flask app -> Option A
  4. Quick Check:

    Missing Blueprint registration causes route errors = B [OK]
Quick Trick: Always register Blueprints with app [OK]
Common Mistakes:
MISTAKES
  • Assuming Blueprint auto-registers
  • Misreading route decorator syntax
  • Ignoring missing return statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes