Challenge - 5 Problems
HTML Forms POST Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when this Flask route receives a POST request?
Consider this Flask route handling a form submission with POST method. What will be the output if the form sends 'username' as 'alice'?
Flask
from flask import Flask, request app = Flask(__name__) @app.route('/submit', methods=['POST']) def submit(): username = request.form.get('username') return f"Hello, {username}!"
Attempts:
2 left
💡 Hint
Remember that request.form contains data sent by POST method from the form.
✗ Incorrect
The route accepts POST requests and extracts 'username' from form data. If the form sends 'alice', the response is 'Hello, alice!'.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a Flask route to handle POST form data?
Select the option that correctly defines a Flask route to accept POST requests and retrieve a form field named 'email'.
Attempts:
2 left
💡 Hint
POST data is accessed via request.form, and the route must allow POST method.
✗ Incorrect
Option D correctly sets methods=['POST'] and accesses form data with request.form['email']. Others either miss POST method or use wrong data source.
🔧 Debug
advanced2:00remaining
Why does this Flask form submission always return 'None' for the username?
Given this Flask route and HTML form, why does the server always respond with 'Hello, None!' even when a username is entered?
Flask
from flask import Flask, request app = Flask(__name__) @app.route('/login', methods=['POST']) def login(): username = request.args.get('username') return f"Hello, {username}!" # HTML form: # <form action="/login" method="post"> # <input type="text" name="username"> # <input type="submit"> # </form>
Attempts:
2 left
💡 Hint
POST form data is in request.form, not request.args.
✗ Incorrect
request.args contains query parameters from URL (GET data). POST form data is in request.form. Using request.args.get('username') returns None.
❓ state_output
advanced2:00remaining
What is the value of 'count' after submitting the form twice?
This Flask app counts how many times the form is submitted. What will be the value of 'count' after two POST submissions?
Flask
from flask import Flask, request app = Flask(__name__) count = 0 @app.route('/submit', methods=['POST']) def submit(): global count count += 1 return f"Submission count: {count}"
Attempts:
2 left
💡 Hint
The global variable 'count' is incremented on each POST request.
✗ Incorrect
The global 'count' variable increments by 1 on each POST. After two submissions, count is 2.
🧠 Conceptual
expert2:00remaining
Which statement about HTML forms with POST method and Flask is TRUE?
Select the true statement about handling HTML forms with POST method in Flask.
Attempts:
2 left
💡 Hint
Check how Flask routes handle HTTP methods and where form data is stored.
✗ Incorrect
Flask's request.form contains POST form data, but request.args contains GET query parameters. The route must allow POST method explicitly. JSON data is accessed via request.get_json(), not request.form.