Bird
0
0

Given the code snippet:

medium📝 component behavior Q13 of 15
Flask - WebSocket and Real-Time
Given the code snippet:
from flask_restx import Api, Namespace, Resource

api = Api()
users_ns = Namespace('users')

@users_ns.route('/profile')
class UserProfile(Resource):
    def get(self):
        return {'user': 'Alice'}

api.add_namespace(users_ns)

What URL path will return the JSON {'user': 'Alice'} when the Flask app runs?
A/api/users/profile
B/profile
C/users/profile
D/users
Step-by-Step Solution
Solution:
  1. Step 1: Understand Namespace route prefix

    The Namespace 'users' prefixes all routes inside it with '/users'. The route defined is '/profile'.
  2. Step 2: Combine Namespace and route paths

    Combining '/users' and '/profile' gives '/users/profile' as the full URL path.
  3. Final Answer:

    /users/profile -> Option C
  4. Quick Check:

    Namespace prefix + route = /users/profile [OK]
Quick Trick: Namespace name prefixes all its routes [OK]
Common Mistakes:
MISTAKES
  • Using route path without namespace prefix
  • Assuming '/api' prefix automatically added
  • Confusing route path with namespace name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes