DRF post url without end slash

北城以北 提交于 2020-12-13 04:26:05

问题


In my application , I need to display the REST url(s) without a slash at the end. I have tried below combination but it didnt work.

Added APPEND_SLASH=True in the settings.py

and on the urls.py file

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

After adding this when I am calling the urls without slash at the end in the postman, it is giving me an 404 error- URL not found. But with slash at the end is working fine.

Is there any option to make this url without with slash at the end ? Especially for the post urls


回答1:


APPEND_SLASH will append it to the request (e.g. mysite/blog --> mysite/blog/). This is not what you want, since your urlconf explicitly says there should be no slash.

Also APPEND_SLASH is True by default. So you need to set it to False instead. That way, if you make a request without a slash, Django won't automatically add in a slash.



来源:https://stackoverflow.com/questions/51356900/drf-post-url-without-end-slash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!