django exceptions code example

Example 1: django.core.exceptions.ImproperlyConfigured

import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'appname.settings')
django.setup()

# all imports must go below here

Example 2: validationerror django params

raise ValidationError(
    _('Invalid value: %(value)s'),
    code='invalid',
    params={'value': '42'},
)

# Multiple validation errors
raise ValidationError([
    ValidationError(_('Error 1'), code='error1'),
    ValidationError(_('Error 2'), code='error2'),
])