Bird
Raised Fist0
Flaskframework~20 mins

What is Flask - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Flask Framework Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is Flask used for?
Flask is a popular tool in Python. What is its main purpose?
ATo manage databases directly without code
BTo build websites and web apps easily with Python
CTo create desktop applications with graphical interfaces
DTo analyze data and create charts
Attempts:
2 left
💡 Hint
Think about what web developers need to create websites.
🧠 Conceptual
intermediate
1:30remaining
Which feature is NOT part of Flask?
Flask provides many features. Which one is NOT included by default?
ARouting to handle different web pages
BSupport for handling HTTP requests and responses
CTemplate rendering to create HTML pages
DBuilt-in database ORM (Object Relational Mapper)
Attempts:
2 left
💡 Hint
Flask is minimal and lets you add extra tools as needed.
❓ component_behavior
advanced
2:00remaining
What happens when you run this Flask code?
Consider this Flask app code. What will the browser show when visiting '/'?
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello, Flask!'

if __name__ == '__main__':
    app.run()
AThe browser shows the text: Hello, Flask!
BThe browser shows a 404 Not Found error
CThe browser shows a blank page
DThe server crashes with an error
Attempts:
2 left
💡 Hint
Look at the route decorator and the returned string.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this Flask snippet
Which option correctly fixes the syntax error in this Flask code? from flask import Flask app = Flask(__name__) @app.route('/') def home() return 'Hi!' app.run()
AAdd parentheses to app.run like app.run()
BChange @app.route('/') to @app.route('/home')
CAdd a colon after def home():
DIndent the return statement one level less
Attempts:
2 left
💡 Hint
Check the function definition line carefully.
❓ lifecycle
expert
2:30remaining
What is the order of events when a Flask app handles a web request?
Put these steps in the correct order when Flask processes a web request: 1. Flask calls the view function 2. Browser sends HTTP request 3. Flask sends HTTP response back 4. Flask matches URL to route
A1,2,3,4
B1,3,2,4
C2,1,3,4
D1,2,4,3
Attempts:
2 left
💡 Hint
Think about what happens first: the browser sends a request or Flask matches routes?

Practice

(1/5)
1. What is Flask primarily used for?
easy
A. Creating desktop applications
B. Building web applications with Python
C. Managing databases directly
D. Designing mobile apps

Solution

  1. Step 1: Understand Flask's purpose

    Flask is a tool that helps developers create web applications using Python.
  2. Step 2: Compare options with Flask's role

    Options A, C, and D describe other types of software development, not Flask's main use.
  3. Final Answer:

    Building web applications with Python -> Option B
  4. Quick Check:

    Flask = Web apps with Python [OK]
Hint: Flask = Python + web apps, not desktop or mobile [OK]
Common Mistakes:
  • Thinking Flask is for desktop apps
  • Confusing Flask with database tools
  • Assuming Flask builds mobile apps
2. Which of the following is the correct way to start a basic Flask app?
easy
A. from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, Flask!'
B. import flask app = flask() @app.route('/') def home(): print('Hello, Flask!')
C. from flask import app app = Flask() @app.route('/') def home(): return 'Hello, Flask!'
D. import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, Flask!'

Solution

  1. Step 1: Check import and app creation

    from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, Flask!' correctly imports Flask and creates an app with Flask(__name__). Others have wrong imports or app creation.
  2. Step 2: Verify route and return statement

    from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, Flask!' uses @app.route('/') and returns a string, which is correct Flask syntax.
  3. Final Answer:

    Correct Flask app start code -> Option A
  4. Quick Check:

    Correct import and route = from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, Flask!' [OK]
Hint: Import Flask and create app with Flask(__name__) [OK]
Common Mistakes:
  • Using wrong import statements
  • Calling flask() instead of Flask()
  • Printing instead of returning response
3. What will this Flask route return when accessed?
from flask import Flask
app = Flask(__name__)

@app.route('/greet')
def greet():
    return 'Welcome to Flask!'
medium
A. Nothing, the route is not defined
B. A syntax error because of missing parentheses
C. A server error due to missing return statement
D. A web page showing 'Welcome to Flask!'

Solution

  1. Step 1: Analyze the route definition

    The route '/greet' is defined with a function that returns the string 'Welcome to Flask!'.
  2. Step 2: Understand Flask response behavior

    Flask sends the returned string as the response body, so visiting '/greet' shows that message.
  3. Final Answer:

    A web page showing 'Welcome to Flask!' -> Option D
  4. Quick Check:

    Route returns string response = A web page showing 'Welcome to Flask!' [OK]
Hint: Returned string is sent as web page content [OK]
Common Mistakes:
  • Thinking return must be HTML tags
  • Assuming missing parentheses cause error
  • Believing route is undefined
4. Identify the error in this Flask app code:
from flask import Flask
app = Flask(__name__)

@app.route('/hello')
def hello():
    print('Hello World')
medium
A. Wrong app creation syntax
B. Incorrect import of Flask
C. Missing return statement in route function
D. Route decorator syntax error

Solution

  1. Step 1: Check the route function body

    The function prints 'Hello World' but does not return anything, so Flask gets no response to send.
  2. Step 2: Understand Flask route requirements

    Flask route functions must return a response string or object; printing does not send data to the client.
  3. Final Answer:

    Missing return statement in route function -> Option C
  4. Quick Check:

    Route must return response, not just print [OK]
Hint: Route functions must return, not print, response [OK]
Common Mistakes:
  • Using print instead of return
  • Assuming print sends response
  • Ignoring missing return causes error
5. You want to create a Flask app that responds differently based on the URL path. Which feature helps you do this?
hard
A. Using multiple @app.route decorators with different paths
B. Using print statements inside one route
C. Creating multiple Flask app instances
D. Changing the Flask import statement

Solution

  1. Step 1: Understand Flask routing

    Flask uses @app.route decorators to map different URL paths to different functions.
  2. Step 2: Evaluate options for handling multiple paths

    Using multiple @app.route decorators with different paths allows different responses for each URL.
  3. Final Answer:

    Using multiple @app.route decorators with different paths -> Option A
  4. Quick Check:

    Multiple routes = different URL responses [OK]
Hint: Use multiple @app.route for different URLs [OK]
Common Mistakes:
  • Thinking print changes URL response
  • Creating multiple app instances unnecessarily
  • Modifying import does not affect routing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard