📜  从 django 读取 api - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:22.741000             🧑  作者: Mango

代码示例1
from django.shortcuts import render
import requests

def github(request):
    user = {}
    if 'username' in request.GET:
        username = request.GET['username']
        url = 'https://api.github.com/users/%s' % username
        response = requests.get(url)
        user = response.json()
    return render(request, 'core/github.html', {'user': user})