How can I make a trailing slash optional on a Django Rest Framework SimpleRouter

后端 未结 5 2068
死守一世寂寞
死守一世寂寞 2021-02-05 02:43

The docs say you can set trailing_slash=False but how can you allow both endpoints to work, with or without a trailing slash?

5条回答
  •  我寻月下人不归
    2021-02-05 03:00

    You can also override this setting by passing a trailing_slash argument to the SimpleRouter constructor as follows:

    from rest_framework import routers
    
    router = routers.SimpleRouter(trailing_slash=False)
    

提交回复
热议问题