How to do it...

To use the system-check framework, follow these simple steps:

  1. Create the checks.py file, with the following content:
# viral_videos/checks.py 
from django.core.checks import Warning, register, Tags


@register(Tags.compatibility)
def settings_check(app_configs, **kwargs):
from django.conf import settings

errors = []

if not settings.ADMINS:
errors.append(Warning(
"""
The system admins are not set in the project settings
""",
obj=settings,
hint="""
In order to receive notifications when new videos are
created, define system admins in your settings, like:

ADMINS = (
("Admin", "[email protected]"),
)
""",
id="viral_videos.W001"))

return errors
  1. Import the checks in the ready() method of the app configuration, as follows:
# viral_videos/apps.py
# ...
class ViralVideosAppConfig(AppConfig):
# ...
def ready(self):
from .signals import inform_administrators
from .checks import settings_check
  1. To try the check that you just created, remove or comment out the ADMINS setting, and then run the check management command in your virtual environment or Docker app container, as follows:
(myproject_env)$ python3 manage.py check
System check identified some issues:

WARNINGS:
<Settings "myproject.settings">: (viral_videos.W001)
The system admins are not set in the project settings

HINT:
In order to receive notifications when new videos are
created, define system admins in your settings, like:

ADMINS = (
("Admin", "[email protected]"),
)


System check identified 1 issue (0 silenced).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.160.61