Complete the code to import the Flask module correctly.
from flask import [1]
The Flask class is imported from the flask module to create the app instance.
Complete the code to define a route that requires a permission check.
@app.route('/dashboard') def dashboard(): if not user.has_permission([1]): return 'Access denied', 403 return 'Welcome to dashboard'
The route checks if the user has the 'admin' permission before allowing access.
Fix the error in the permission check condition.
if user.has_permission([1]): return 'Access granted' else: return 'Access denied', 403
The permission name must be a string, so it needs quotes around 'admin'.
Fill both blanks to create a decorator that checks for 'editor' permission before running the route function.
def permission_required([1]): def decorator(f): def wrapper(*args, **kwargs): if not user.has_permission([2]): return 'Forbidden', 403 return f(*args, **kwargs) return wrapper return decorator
The decorator takes a permission name as argument and checks if the user has that permission before calling the route function.
Fill all three blanks to create a route with permission check using the decorator.
@app.route('/edit') @permission_required([1]) def edit(): return 'Edit page for [2]' user = User([3])
The route '/edit' requires 'editor' permission. The user named 'Alice' has 'admin' permission.