DRF发布网址,不带斜杠 [英] DRF post url without end slash

查看:86
本文介绍了DRF发布网址,不带斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要显示REST网址(末尾没有斜杠).我试过下面的组合,但没有用.

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.

在settings.py中添加了 APPEND_SLASH = True .

Added APPEND_SLASH=True in the settings.py

以及urls.py文件

and on the urls.py file

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

当我在邮递员的末尾使用不带斜杠的url进行添加后,它给了我一个404错误-URL找不到.但是最后用斜杠可以正常工作.

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.

是否有任何选项可以使此url末尾不带斜杠?尤其是帖子网址

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

推荐答案

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.

默认情况下,APPEND_SLASH也为True.因此,您需要将其设置为False.这样,如果您在不加斜杠的情况下发出请求,则Django不会自动添加斜杠.

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.

这篇关于DRF发布网址,不带斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆