INSTALLED_APPS += ['silk']
MIDDLEWARE += ['silk.middleware.SilkyMiddleware']
# Silk configuration
SILKY_PYTHON_PROFILER = True
SILKY_PYTHON_PROFILER_BINARY = True
SILKY_MAX_REQUEST_BODY_SIZE = -1 # Silk takes anything
SILKY_MAX_RESPONSE_BODY_SIZE = -1
SILKY_INTERCEPT_PERCENT = 100 # Profile all requests in dev
if settings.DEBUG:
urlpatterns += [path('silk/', include('silk.urls', namespace='silk'))]
from silk.profiling.profiler import silk_profile
@silk_profile(name='Complex Calculation')
def complex_calculation(data):
# Expensive operation
result = process(data)
return result
Django Silk profiles SQL queries, HTTP requests, and Python code. I install it in development to identify bottlenecks. It shows query counts, execution times, and duplicate queries per request. The web UI visualizes performance data. I use @silk_profile() decorator for specific functions. Silk helps find N+1 queries and slow endpoints. For production, I use APM tools like New Relic or Datadog. Silk's detailed insights make optimization straightforward. I remove it or disable in production to avoid overhead.