[{"id":"flaskbeginner-001","courseId":"flask-beginner","domain":"routing-and-requests","topic":"route() decorator","prompt":"A view function is decorated with @app.route('/hello'). What does that decorator do?","hint":"Think about how a server decides which function answers a request.","explain":"In Flask, a Python function answers each web request. A decorator above a function can attach extra information to it. Consider what a server needs to pick the right function for a path.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#routing","interaction":{"type":"single"},"options":[{"id":"a","text":"It binds the function to the URL /hello, so requests to that path call it","why":"route() registers the path, and Flask calls the function whenever a request for that path arrives."},{"id":"b","text":"It runs the function once at startup and caches what it returns","whyNot":"The function runs for each matching request; route() does no caching."},{"id":"c","text":"It serves a file named hello from the static folder","whyNot":"Static files are served under their own URL rule; route() maps a path to a function."},{"id":"d","text":"It runs the function before every request in the whole app","whyNot":"That job belongs to a before_request hook; route() only matches one path."}],"answer":"a","explanation":"The route() decorator registers a URL rule that maps a path to the decorated view function, which Flask calls for matching requests.","concept":"The route() decorator registers a URL rule that maps a path to the decorated view function, which Flask calls for matching requests.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"@app.route('/hello')\ndef hello():\n    return 'Hello, World'","takeaways":["route() maps a URL path to a view function; that function answers requests for the path."]},{"id":"flaskbeginner-002","courseId":"flask-beginner","domain":"routing-and-requests","topic":"Variable URL parts","prompt":"A view is declared with @app.route('/user/<username>'), and a visitor opens /user/alice. How does the view function receive the value alice?","hint":"Think about what the view function's parameter list must contain for the value to arrive.","explain":"A route can mark part of its address as a placeholder, so one rule matches many addresses. The matched text must still reach the function; consider which way of passing a value fits a placeholder with a name.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#variable-rules","interaction":{"type":"single"},"options":[{"id":"a","text":"As a positional argument, the first one in the call","whyNot":"Flask does not pass the value by position; it hands the value over under the variable's name."},{"id":"b","text":"As a keyword argument named after the variable","why":"Your function receives the variable part as a keyword argument, so its parameter must carry the same name."},{"id":"c","text":"In request.args under the variable's name","whyNot":"request.args holds ?key=value data from the query string; a variable part of the path goes to the view instead."},{"id":"d","text":"As a list of the path's segments","whyNot":"The view receives the variable part as one keyword argument, not as a list of segments."}],"answer":"b","explanation":"Each variable part of a route is passed to the view function as a keyword argument with the same name as the variable.","concept":"Each variable part of a route is passed to the view function as a keyword argument with the same name as the variable.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"@app.route('/user/<username>')\ndef show_user(username):\n    return f'User {username}'","takeaways":["A route's <name> part arrives in the view as a keyword argument called name."]},{"id":"flaskbeginner-003","courseId":"flask-beginner","domain":"routing-and-requests","topic":"Trailing slashes in rules","prompt":"A view is declared with @app.route('/about'), which has no trailing slash. A visitor requests /about/ with a trailing slash, and Flask still returns that view's page.","hint":"Compare the address in the decorator with the address the visitor typed, character by character.","explain":"A route's address is matched as an exact pattern, and a final slash is one character of that pattern. Think about what happens when a visitor's address differs from the rule only by that character.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#unique-urls-redirection-behavior","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Flask does not ignore the final slash: /about/ gets a 404 Not Found error."},{"id":"b","text":"False","why":"A rule without a trailing slash matches only that address; requesting it with a slash produces a 404 Not Found error."}],"answer":"b","explanation":"A rule written without a trailing slash answers only that exact address; requesting it with a trailing slash gives a 404 Not Found error.","concept":"A rule written without a trailing slash answers only that exact address; requesting it with a trailing slash gives a 404 Not Found error.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A rule written without a trailing slash answers only that exact address; adding the slash gives a 404 error."]},{"id":"flaskbeginner-004","courseId":"flask-beginner","domain":"routing-and-requests","topic":"Default GET method","prompt":"A view is declared as @app.route('/contact') with no methods argument. Which request method does it answer by default?","hint":"Think about what the decorator assumes when the methods argument is missing.","explain":"Each web request names a method, such as one for reading a page or one for sending data. A route decides which methods it accepts, and when you leave that decision out, a default applies.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#http-methods","interaction":{"type":"single"},"options":[{"id":"a","text":"GET","why":"By default a route only answers GET requests; other methods must be listed in methods."},{"id":"b","text":"POST","whyNot":"POST is for submitting data, and a route accepts it only when you list it."},{"id":"c","text":"GET and POST","whyNot":"Adding POST needs an explicit methods list or a post() shortcut; the default does not include it."},{"id":"d","text":"Every HTTP method","whyNot":"Flask does not open a route to all methods; it answers only GET until you say otherwise."}],"answer":"a","explanation":"A route with no methods argument answers only GET; listing other methods, or using shortcuts such as post(), adds them.","concept":"A route with no methods argument answers only GET; listing other methods, or using shortcuts such as post(), adds them.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"@app.route('/contact')\ndef contact():\n    return 'Contact page'","takeaways":["A route answers only GET unless its methods argument, or a shortcut like post(), adds more."]},{"id":"flaskbeginner-005","courseId":"flask-beginner","domain":"routing-and-requests","topic":"methods argument","prompt":"A login page must answer both GET and POST requests. Which TWO of these declarations do that correctly?","hint":"Check the name of the argument and the type of value it takes.","explain":"Each web request carries a method, and a route answers only the methods it has been set up to accept. Flask gives you more than one way to declare that set, and each way has its own exact form.","source":"https://flask.palletsprojects.com/en/stable/quickstart/#http-methods","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"@app.post('/login')","whyNot":"post() answers only POST, so GET requests still need a route of their own."},{"id":"b","text":"@app.route('/login', methods=['GET', 'POST'])","why":"The methods argument takes a list of method names, so one function can answer both."},{"id":"c","text":"@app.route('/login', method='POST')","whyNot":"The argument is named methods, plural; method= is not the documented argument."},{"id":"d","text":"@app.get('/login') on one function and @app.post('/login') on another","why":"Flask's shortcut decorators let each method have its own function, as the docs show."},{"id":"e","text":"@app.route('/login', methods='GET,POST')","whyNot":"methods expects a list; a string is read character by character, so the names come out wrong."},{"id":"f","text":"@app.route('/login', only=['GET', 'POST'])","whyNot":"There is no only argument; the list of methods goes in methods."}],"answer":"bd","explanation":"The methods argument takes a list of method names; the get() and post() shortcuts each declare one method on a separate function.","concept":"The methods argument takes a list of method names; the get() and post() shortcuts each declare one method on a separate function.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Pass methods=[...] as a list; use separate get() and post() views when each method needs its own code."]}]