core.checks.register()

register(*tags)(function)

You can pass as many tags to register as you want in order to label your check. Tagging checks is useful since it allows you to run only a certain group of checks. For example, to register a compatibility check, you would make the following call:

from django.core.checks import register, Tags

@register(Tags.compatibility)
def my_check(app_configs, **kwargs):
    # ... perform compatibility checks and collect errors
    return errors

You can register “deployment checks” that are only relevant to a production settings file like this:

@register(Tags.security, deploy=True)
def my_check(app_configs, **kwargs):
    ...

These checks will only be run if the check --deploy option is used.

You can also use register as a function rather than a decorator by passing a callable object (usually a function) as the first argument to register.

The code below is equivalent to the code above:

def my_check(app_configs, **kwargs):
    ...
register(my_check, Tags.security, deploy=True)
doc_Django
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.