【发布时间】:2018-11-02 16:07:17
【问题描述】:
我正在使用 Python(3.6) 开发一个项目,我需要在其中实现 GitHub API。 我尝试过使用 JSON api:
来自views.py:
class GhNavigator(CreateView):
def get(self, request, *args, **kwargs):
term = request.GET.get('search_term')
username = 'arycloud'
token = 'API_TOKEN'
login = requests.get('https://api.github.com/search/repositories?q=' + term, auth=(username, token))
print(login)
return render(request, 'navigator/template.html', {'login': login})
但它只是返回status 200,我想获取用户传递的term 的存储库列表。
我怎样才能做到这一点?
请帮帮我!
提前致谢!
【问题讨论】:
-
打印什么?你有什么要求?您可能应该调用
login.json来获取其中包含的内容。 -
当我打印
login.json它返回<bound method Response.json of <Response [200]>> -
.json是一个函数,所以你应该调用它(即login.json())。 -
它是否也包含提交?
-
这取决于 API 的使用方式。我认为您应该检查 GitHub API 文档。但是我自己的一个快速实验,并没有立即产生提交。
标签: python django python-requests github-api