When accessing /product/abc/19.99, what error occurs?
medium
A. ValueError because 'abc' is not an integer
B. TypeError because price is not a float
C. No error, it works fine
D. 404 Not Found error due to URL mismatch
Solution
Step 1: Check the int converter requirement
The first parameter expects an integer, but 'abc' is not an integer.
Step 2: Understand Flask routing behavior on type mismatch
Flask does not raise ValueError but returns 404 Not Found if the URL does not match the route pattern.
Final Answer:
404 Not Found error due to URL mismatch -> Option D
Quick Check:
Type mismatch in route = 404 error [OK]
Hint: Wrong type in URL parameter causes 404, not exception [OK]
Common Mistakes:
Expecting Python exceptions instead of 404
Confusing ValueError with Flask routing errors
Assuming route matches any string
5. You want to create a Flask route that accepts a file path parameter which may include slashes, and an integer version number after it, like /download/docs/manual/2. Which route definition correctly uses converters to achieve this?
hard
A. @app.route('/download/<path:filepath>/<int:version>')
B. @app.route('/download/<int:version>/<path:filepath>')
C. @app.route('/download/<path:filepath><int:version>')
D. @app.route('/download/<path:filepath>/<float:version>')
Solution
Step 1: Identify the order of parameters in the URL
The URL pattern is /download/ followed by a path (which may include slashes), then a slash, then an integer version.
Step 2: Use path for filepath and int for version in correct order
The route must be /download/<path:filepath>/<int:version> to match the URL structure.
Final Answer:
@app.route('/download/<path:filepath>/<int:version>') -> Option A
Quick Check:
path then int in route matches URL structure [OK]
Hint: Use path converter before int for multi-part paths [OK]
Common Mistakes:
Swapping parameter order
Missing slash between parameters
Using float instead of int for version
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.