Flask Fundamentals: Test Your Python Web Knowledge! Quiz

  1. Basic Flask Import

    Which code snippet correctly imports the Flask class from the flask library?

    1. A. from flask import Flask
    2. B. import Flask from flask
    3. C. from Flask import flask
    4. D. import flask.Flask
    5. E. from flask import flaskk
  2. Running the Flask App

    Which of the following is the correct way to run a Flask app if your app variable is named 'app'?

    1. A. app.run()
    2. B. Flask.run()
    3. C. flask.app.run()
    4. D. run(app)
    5. E. run_flask(app)
  3. Route Decoration

    What is the correct decorator to define a route for the URL '/' in Flask?

    1. A. @app.route('/')
    2. B. $$route('/')
    3. C. @route.app('/')
    4. D. route:app('/')
    5. E. @@app.route('/')
  4. Returning Responses

    If a function returns 'Hello, World!' in Flask, what is the correct function signature for the route?

    1. A. def hello(): return 'Hello, World!'
    2. B. func hello(): return 'Hello, World!'
    3. C. def hello: return 'Hello, World!'
    4. D. hello() =u003E 'Hello, World!'
    5. E. function hello(): return 'Hello, World!'
  5. Dynamic Routes

    How can you define a route that takes a username as a string variable in the URL?

    1. A. @app.route('/user/u003Cusernameu003E')
    2. B. @app.route('/user/[username]')
    3. C. @app.route('/user/{username}')
    4. D. @app.route('/user/username')
    5. E. @app.route('/user/$username')
  6. HTTP Methods

    To make a Flask route accept both GET and POST methods, which parameter should be added to the @app.route decorator?

    1. A. methods=['GET', 'POST']
    2. B. allow=['GET, POST']
    3. C. verbs=['GET','POST']
    4. D. http_methods=['GET','POST']
    5. E. allowed=['GET', 'POST']
  7. Accessing Form Data

    Which method do you use to retrieve submitted form data called 'email' in a Flask view?

    1. A. request.form['email']
    2. B. request.get('email')
    3. C. req.form['email']
    4. D. form.email
    5. E. request.email
  8. Debug Mode

    What argument should you pass to app.run() to enable Flask's debug mode?

    1. A. debug=True
    2. B. run_debug=True
    3. C. enable_debug=True
    4. D. flask_debug=True
    5. E. debugg=True
  9. Template Rendering

    Which function should you use to render an HTML template called 'index.html'?

    1. A. render_template('index.html')
    2. B. renderHTML('index.html')
    3. C. display_template('index.html')
    4. D. flask.render_html('index.html')
    5. E. app.show_template('index.html')
  10. URL Building

    If you have a Flask view function named 'profile', which built-in function generates its URL?

    1. A. url_for('profile')
    2. B. build_url('profile')
    3. C. make_url('profile')
    4. D. profile.url()
    5. E. create_url('profile')