I am new to using django and am unfamiliar as to how my question should be worded.
I have been working on a new web app but noticed that the initial loading of the website is slow. My current view code is here.
from jinja2 import Environment, FileSystemLoader
from django.http import HttpResponse
from tools import fetcher
import requests
import json
def index(request):
env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('index.html')
template_values = {'popular_stocks': []}
popular = fetcher.get_tops()
for instrument in popular:
r = requests.get('https://api.iextrading.com/1.0/stock/%s/quote' % (instrument['symbol']))
quote = json.loads(r.content.decode('utf-8'))
template_values['popular_stocks'].append(quote)
return HttpResponse(template.render(template_values))
Is there anyway to speed up the loading of my site by loading the initial index.html first WITHOUT any popularstocks and then submitting the fetcher.get_tops() to the template values?
I know of AJAX but I am unsure how to implement it or if that is even what I need.
Any step towards the right direction would be appreciated.