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.
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.
Final Answer:
Correct Flask app start code -> Option A
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
Step 1: Analyze the route definition
The route '/greet' is defined with a function that returns the string 'Welcome to Flask!'.
Step 2: Understand Flask response behavior
Flask sends the returned string as the response body, so visiting '/greet' shows that message.
Final Answer:
A web page showing 'Welcome to Flask!' -> Option D
Quick Check:
Route returns string response = A web page showing 'Welcome to Flask!' [OK]
Hint: Returned string is sent as web page content [OK]