失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 使用rest_framework的routers模块添加路由

使用rest_framework的routers模块添加路由

时间:2023-11-21 06:25:46

相关推荐

使用rest_framework的routers模块添加路由

1、修改路由管理urls.py文件

1)引用

from rest_framework.routers import DefaultRouter

2)路由注册

router = DefaultRouter()

router.register(r'hellotest', helloViewset, base_name="r'hellotest")

3)修改urlpatterns

新增:url(r'^', include(router.urls))

4)测试

使用postMan测试,返回信息,可以使用show出来的路由,继续其他信息查看。

HTTP 200 OKAllow:GET, HEAD, OPTIONSContent-Type:application/jsonVary:Accept{"eastcarstest": "http://127.0.0.1:8000/hellotest/"}

如果觉得《使用rest_framework的routers模块添加路由》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。