I have a problem on retrieving the data from database, I'm using Mysql database and one table which contains 15 fields which I'm going to display it on template in a table.
It has more than 4 million records in the table,
def index(request):
args = {}
data = Mymodel.objects.all()
args['data'] = data
return render(request, 'index.html', args)
I tried this way but the data loads very very slowly,
and next approach I tried for database connections
def index(request):
args = {}
sql = "select * from mymodel"
cursor = connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
args['result'] = result
return render(request, 'index.html', args)
This also does the same, I need to load the data much faster. Please suggest to me any approach that would load the data faster.