I don’t know yours models… let’s asume:
models.py
from django.db import models
class Uuser(models.Model):
name = models.CharField(max_length=45,)
public_repos = models.CharField(max_length=45,)
then in your view.py
from django.shortcuts import render
import requests
from models import Uuser
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()
usr = Uuser(name=user['name'], public_repos=user['public_repos']) # create new model instance
usr.save() #seve to db
return render(request, 'core/github.html', {'user': user})
I’m not checking if that exact name exist in db so there will be new record on the same name each time you post it to view.
CLICK HERE to find out more related problems solutions.