[{"id":"flaskintermediate-001","courseId":"flask-intermediate","domain":"routing-and-requests","topic":"Trailing slash redirects","prompt":"A route is declared as '/projects/' with a trailing slash. A visitor opens /projects without the slash. What does Flask do?","hint":"Flask treats one of the two spellings as the canonical URL.","explain":"A rule that ends in a slash behaves like a folder; one without it behaves like a file. Flask keeps one canonical spelling per rule and treats the other spelling of that address differently.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#unique-urls-redirection-behavior","interaction":{"type":"single"},"options":[{"id":"a","text":"Sends the visitor to /projects/ with the slash","why":"The slash form is the canonical URL, so Flask sends requests without the slash there."},{"id":"b","text":"Serves the page directly at /projects","whyNot":"Flask does not serve a second copy; it points the client at the canonical URL instead."},{"id":"c","text":"Returns 404 Not Found","whyNot":"A 404 is what a trailing-slash request gets on a rule written without the slash."},{"id":"d","text":"Returns 405 Method Not Allowed","whyNot":"405 means the route rejects the HTTP method; the slash is not a method problem."}],"answer":"a","explanation":"A rule with a trailing slash has a canonical URL with the slash; requests without it are redirected there. A rule without the slash returns 404 when requested with one.","concept":"A rule with a trailing slash has a canonical URL with the slash; requests without it are redirected there. A rule without the slash returns 404 when requested with one.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A rule ending in a slash redirects slashless requests; a rule without one answers 404 to a trailing-slash request."]},{"id":"flaskintermediate-002","courseId":"flask-intermediate","domain":"routing-and-requests","topic":"Path converter","prompt":"Which TWO statements about URL converters in Flask routes are correct?","hint":"Each converter says what kind of value it will accept.","explain":"A variable part of a route can carry a converter prefix. The converter limits what text the variable may contain and sets the Python type the view receives, and each one draws its boundaries differently.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#variable-rules","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The default converter matches text that has no slash","why":"A variable with no converter is a string, which accepts any text without a slash."},{"id":"b","text":"The path converter also matches values that contain slashes","why":"path works like the default but also accepts slashes, so it can span folders."},{"id":"c","text":"The int converter accepts negative numbers too","whyNot":"int accepts positive integers, so a negative value does not match."},{"id":"d","text":"A variable with no converter is treated as an int","whyNot":"The default is string, not int; numbers need the int converter."},{"id":"e","text":"The uuid converter accepts any text","whyNot":"uuid accepts UUID strings, so arbitrary text does not match."},{"id":"f","text":"The float converter accepts negative values","whyNot":"float accepts positive floating point values only."}],"answer":"ab","explanation":"The default string converter matches text without a slash; the path converter is the same but also accepts slashes. int and float accept positive values.","concept":"The default string converter matches text without a slash; the path converter is the same but also accepts slashes. int and float accept positive values.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Pick path only when a value really spans folders; the default converter stops at the first slash."]},{"id":"flaskintermediate-003","courseId":"flask-intermediate","domain":"routing-and-requests","topic":"url_for extra arguments","prompt":"A view calls url_for('login', next='/home'), but the login rule has no variable part called next. What does the generated URL look like?","hint":"Think about what happens to a keyword that matches no variable part of the rule.","explain":"url_for builds a URL from an endpoint name and keyword values. A value that matches a placeholder in the rule fills that spot, and a value with no placeholder is carried some other way.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#url-building","interaction":{"type":"single"},"options":[{"id":"a","text":"/login?next=/home","why":"Unknown keyword arguments are appended to the URL as query parameters."},{"id":"b","text":"/login/next/home","whyNot":"Extra values are not turned into path segments; only the rule's variable parts go in the path."},{"id":"c","text":"/login","whyNot":"The extra value is not dropped; url_for keeps it as a query parameter."},{"id":"d","text":"A TypeError is raised","whyNot":"url_for accepts any keyword arguments, and the unmatched ones go to the query string."}],"answer":"a","explanation":"url_for fills the rule's variable parts from matching keyword arguments and appends any unknown ones as query string parameters.","concept":"url_for fills the rule's variable parts from matching keyword arguments and appends any unknown ones as query string parameters.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Keywords matching a rule variable fill the path; any other keyword becomes a query parameter."]},{"id":"flaskintermediate-004","courseId":"flask-intermediate","domain":"routing-and-requests","topic":"url_for external URLs","prompt":"In Flask's url_for, an external URL is one that carries only the path, such as /login, with no scheme or domain.","hint":"Think about which parts a full address needs beyond the path.","explain":"url_for can produce a path that stays inside the site or a full address usable from anywhere. The _external argument selects between these two forms, and the docs describe what a full address must contain.","source":"https://flask.palletsprojects.com/en/stable/api/#flask.url_for","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The docs say external URLs include the scheme and domain, so a bare path is not an external URL."},{"id":"b","text":"False","why":"The docs define an external URL as one that includes the scheme and domain, so a bare path does not qualify."}],"answer":"b","explanation":"The url_for docs define an external URL as one that includes the scheme and domain; a bare path such as /login is not external.","concept":"The url_for docs define an external URL as one that includes the scheme and domain; a bare path such as /login is not external.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["An external URL includes the scheme and domain, so use _external=True for links opened outside the site, such as in email."]},{"id":"flaskintermediate-005","courseId":"flask-intermediate","domain":"routing-and-requests","topic":"request.json parsing","prompt":"A client sends a valid JSON body to a view that reads request.json, but it forgets to set the Content-Type header. What does Flask return?","hint":"Look at what the header tells Flask about the body.","explain":"Flask decodes a request body as JSON only when the request declares that type. A body that is declared as JSON but cannot be parsed is a separate problem, with its own status code.","source":"https://flask.palletsprojects.com/en/stable/patterns/javascript/#receiving-json-in-views","interaction":{"type":"single"},"options":[{"id":"a","text":"415 Unsupported Media Type","why":"request.json raises 415 when the Content-Type header is not application/json."},{"id":"b","text":"400 Bad Request","whyNot":"400 is raised when the body is not valid JSON, which is a different failure."},{"id":"c","text":"The body is parsed as JSON anyway","whyNot":"Flask does not guess the body type; without the header it refuses to decode the body as JSON."},{"id":"d","text":"500 Internal Server Error","whyNot":"A missing header is a client mistake that Flask reports with a 4xx status, not a server crash."}],"answer":"a","explanation":"request.json requires a Content-Type of application/json; without it Flask raises 415, and a body that is not valid JSON raises 400.","concept":"request.json requires a Content-Type of application/json; without it Flask raises 415, and a body that is not valid JSON raises 400.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Send Content-Type: application/json with JSON bodies, or request.json fails with 415 before parsing."]}]