Hint: Avoid including the same router twice with same prefix [OK]
Common Mistakes:
Thinking router must be included before endpoints
Believing prefix is mandatory or must be omitted
Confusing variable naming with functionality
5. You have two routers: user_router with prefix /users and item_router with prefix /items. You want to include both in your FastAPI app and add tags for automatic docs grouping. Which code snippet correctly includes both routers with tags?
hard
A. app.include_router(user_router, prefix='/users', tags='users')
app.include_router(item_router, prefix='/items', tags='items')
B. app.include_router(user_router, prefix='/users')
app.include_router(item_router, prefix='/items')
app.tags = ['users', 'items']
C. app.include_router(user_router, prefix='/users', tags=['users'])
app.include_router(item_router, prefix='/items', tags=['items'])
D. app.include_router(user_router, tags=['users'])
app.include_router(item_router, tags=['items'])
Solution
Step 1: Check how to add tags when including routers
Tags are passed as a list to the tags argument in include_router.
Step 2: Verify prefix and tags usage for both routers
Each router is included with its prefix and tags as lists, e.g., tags=['users'].
Final Answer:
app.include_router(user_router, prefix='/users', tags=['users'])
app.include_router(item_router, prefix='/items', tags=['items']) -> Option C
Quick Check:
Tags must be lists in include_router calls [OK]
Hint: Pass tags as list when including routers for docs grouping [OK]
Common Mistakes:
Passing tags as string instead of list
Setting tags on app instead of routers
Omitting tags argument entirely
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.