Performance: What is Django
Django affects server-side page generation speed and how quickly content is sent to the browser, impacting initial load time.
def view(request): data = Model.objects.all()[:20] # limit to 20 items return render(request, 'template.html', {'data': data})
def view(request): data = Model.objects.all() return render(request, 'template.html', {'data': data})
| Pattern | Server Processing | Network Transfer | Browser Rendering | Verdict |
|---|---|---|---|---|
| Fetching all data without limits | High CPU and DB load | Large HTML size | Normal | [X] Bad |
| Limiting data and caching | Low CPU and DB load | Smaller HTML size | Normal | [OK] Good |
from django.http import HttpResponse
def home(request):
return HttpResponse('Hello, Django!')from django.http import HttpResponse
def greet(request):
return HttpResponse('Welcome to Django!')
print('Greet function called')Pass the test and this pattern moves unknown