0
0
Flaskframework~10 mins

Flask vs Django decision - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a basic Flask app that returns 'Hello World!'.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return [1]
Drag options to blanks, or click blank then click option'
Aprint('Hello World!')
BHello World!
C'Hello World!'
Dreturn 'Hello World!'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Using print instead of return.
2fill in blank
medium

Complete the code to import Django's HttpResponse class.

Flask
from django.http import [1]
Drag options to blanks, or click blank then click option'
AHttpResponse
BHttpServer
CHttpHandler
DHttpRequest
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing HttpRequest with HttpResponse.
Using incorrect class names.
3fill in blank
hard

Fix the error in this Flask route decorator to respond to the URL '/welcome'.

Flask
@app.route([1])
def welcome():
    return 'Welcome!'
Drag options to blanks, or click blank then click option'
A'/welcome'
B'welcome'
C/welcome
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash.
Not using quotes around the path.
4fill in blank
hard

Fill both blanks to create a Django view that returns 'Hello Django!'.

Flask
from django.http import [1]

def hello(request):
    return [2]('Hello Django!')
Drag options to blanks, or click blank then click option'
AHttpResponse
BHttpRequest
DHttpServer
Attempts:
3 left
💡 Hint
Common Mistakes
Importing HttpRequest instead of HttpResponse.
Returning a string directly instead of an HttpResponse object.
5fill in blank
hard

Fill all three blanks to create a Flask app with a route '/greet' that returns 'Greetings!'.

Flask
from flask import [1]
app = [2](__name__)

@app.route([3])
def greet():
    return 'Greetings!'
Drag options to blanks, or click blank then click option'
AFlask
C'/greet'
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'request' instead of 'Flask'.
Not using quotes around the route path.