Issue
The docs say you can set trailing_slash=False
but how can you allow both endpoints to work, with or without a trailing slash?
Solution
You can override the __init__
method of the SimpleRouter class:
from rest_framework.routers import SimpleRouter
class OptionalSlashRouter(SimpleRouter):
def __init__(self):
super().__init__()
self.trailing_slash = '/?'
The ?
character will make the slash optional for all available routes.
Answered By - Ryan Allen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.