Home:ALL Converter>Make API call on page load (Django)

Make API call on page load (Django)

Ask Time:2021-12-24T21:53:36         Author:moejoe125

Json Formatter

I'm building a basic Django site. Currently, I'm trying figure out a way to make an API call and retrieve the results on page load. Is it possible to use the js .onload function to call a Django view function?

Any suggestions/tips would be appreciated!

Author:moejoe125,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/70473585/make-api-call-on-page-load-django
elkhayyat :

you can use "requests" library and making a request on the django view for this page.\nimport requests\n\ndef my_view(request):\n r = requests.get('https://api.github.com/user', auth=('user', 'pass'))\n context = {\n 'data': r.json()\n }\n return render(request, 'my_html.html', context)\n",
2021-12-24T14:00:17
yy