如何在Django rest框架中传递URL参数并使用GET请求方法获取值

e0bqpujr  于 2022-11-26  发布在  Go
关注(0)|答案(1)|浏览(102)

我希望以http://localhost:8000/api/projects/?id=2021&a=2&b=3&c=4的格式传递url参数,并在视图函数中获取值

js5cn81o

js5cn81o1#

在DRF中,您可以获得如下烫发值...

URL = http://localhost:8000/api/projects/?id=2021&a=2&b=3&c=4

 id = request.query_params.get('id')
 a = request.query_params.get('a')
 b = request.query_params.get('b')
 c = request.query_params.get('c')

 print(id,a,b,c)

Postman 屏幕

相关问题