Performance: HttpResponse object
MEDIUM IMPACT
This affects server response time and how quickly the browser receives and starts rendering content.
from django.http import HttpResponse def view(request): lines = ['Line ' + str(i) for i in range(10000)] content = '\n'.join(lines) return HttpResponse(content)
from django.http import HttpResponse def view(request): content = '' for i in range(10000): content += 'Line ' + str(i) + '\n' return HttpResponse(content)
| Pattern | Server CPU | Memory Usage | Response Time | Verdict |
|---|---|---|---|---|
| String concatenation in loop | High | High | Slow | [X] Bad |
| List comprehension + join | Low | Low | Faster | [OK] Good |
| Read whole large file | High | High | Slow | [X] Bad |
| StreamingHttpResponse | Low | Low | Fast | [OK] Good |