Created
October 16, 2022 17:20
-
-
Save gitaarik/d3a7571434d704c357820e71967574ca to your computer and use it in GitHub Desktop.
Django system check for checking whether Silk is enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.core.checks import Info, register | |
from django.urls import reverse | |
@register() | |
def django_silk(app_configs, **kwargs): | |
""" | |
Checks whether Django Silk is enabled in settings and shows a message if | |
it is. | |
This is useful because you might enable Silk sometimes and then forget to | |
disable it, and it can have an impact on the performance of the development | |
server. | |
""" | |
errors = [] | |
if 'silk' in settings.INSTALLED_APPS: | |
silk_url = reverse('silk:summary') | |
errors.append( | |
Info( | |
f"Django Silk is enabled. Results can be seen in {silk_url}", | |
hint=( | |
"To disable Django Silk, remove the 'silk' app from " | |
"`INSTALLED_APPS`. When you don't need Silk, it's better to " | |
"disable it to save resources." | |
), | |
id='silk.I001', | |
) | |
) | |
if getattr(settings, 'SILKY_PYTHON_PROFILER', False): | |
profiling_url = reverse('silk:profiling') | |
errors.append( | |
Info( | |
f"Django Silk Python Profiler is enabled. Results can be seen in {profiling_url}", | |
hint=( | |
"To disable the profiler, set the `SILKY_PYTHON_PROFILER` " | |
"setting to `False`. When you don't need profiling, it's " | |
"better to disable it to save resources." | |
), | |
id='silk.I002', | |
) | |
) | |
return errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment