【发布时间】:2019-12-27 05:46:31
【问题描述】:
TypeError:只能将str(不是“builtin_function_or_method”)连接到str
在第 5 行:
resp = requests.get(BASE_URL + ENDPOINT + id + '/')
我的代码:
import requests
BASE_URL = 'http://127.0.0.1:8000/'
ENDPOINT = 'api/'
def get_resource(id):
resp = requests.get(BASE_URL + ENDPOINT + id + '/')
print(resp.status_code)
data = resp.json()
print(data)
get_resource(id)
【问题讨论】:
-
id 的值是多少?
-
id 持有整数
-
使用
str(id)函数转换整数值。
标签: rest django-rest-framework active-model-serializers