Basic Flask Import
Which code snippet correctly imports the Flask class from the flask library?
- A. from flask import Flask
- B. import Flask from flask
- C. from Flask import flask
- D. import flask.Flask
- E. from flask import flaskk
Running the Flask App
Which of the following is the correct way to run a Flask app if your app variable is named 'app'?
- A. app.run()
- B. Flask.run()
- C. flask.app.run()
- D. run(app)
- E. run_flask(app)
Route Decoration
What is the correct decorator to define a route for the URL '/' in Flask?
- A. @app.route('/')
- B. $$route('/')
- C. @route.app('/')
- D. route:app('/')
- E. @@app.route('/')
Returning Responses
If a function returns 'Hello, World!' in Flask, what is the correct function signature for the route?
- A. def hello(): return 'Hello, World!'
- B. func hello(): return 'Hello, World!'
- C. def hello: return 'Hello, World!'
- D. hello() =u003E 'Hello, World!'
- E. function hello(): return 'Hello, World!'
Dynamic Routes
How can you define a route that takes a username as a string variable in the URL?
- A. @app.route('/user/u003Cusernameu003E')
- B. @app.route('/user/[username]')
- C. @app.route('/user/{username}')
- D. @app.route('/user/username')
- E. @app.route('/user/$username')
HTTP Methods
To make a Flask route accept both GET and POST methods, which parameter should be added to the @app.route decorator?
- A. methods=['GET', 'POST']
- B. allow=['GET, POST']
- C. verbs=['GET','POST']
- D. http_methods=['GET','POST']
- E. allowed=['GET', 'POST']
Accessing Form Data
Which method do you use to retrieve submitted form data called 'email' in a Flask view?
- A. request.form['email']
- B. request.get('email')
- C. req.form['email']
- D. form.email
- E. request.email
Debug Mode
What argument should you pass to app.run() to enable Flask's debug mode?
- A. debug=True
- B. run_debug=True
- C. enable_debug=True
- D. flask_debug=True
- E. debugg=True
Template Rendering
Which function should you use to render an HTML template called 'index.html'?
- A. render_template('index.html')
- B. renderHTML('index.html')
- C. display_template('index.html')
- D. flask.render_html('index.html')
- E. app.show_template('index.html')
URL Building
If you have a Flask view function named 'profile', which built-in function generates its URL?
- A. url_for('profile')
- B. build_url('profile')
- C. make_url('profile')
- D. profile.url()
- E. create_url('profile')