|
| 1 | +title: django.core.exceptions ImproperlyConfigured Examples |
| 2 | +category: page |
| 3 | +slug: django-core-exceptions-improperlyconfigured |
| 4 | +sortorder: 50030 |
| 5 | +toc: False |
| 6 | +sidebartitle: django.core.exceptions ImproperlyConfigured |
| 7 | +meta: Python code examples for the ImproperlyConfigured exception class provided by the Django codebase. |
| 8 | + |
| 9 | + |
| 10 | +# django.core.exceptions ImproperlyConfigured Examples |
| 11 | +[ImproperlyConfigured](https://github.com/django/django/blob/master/django/core/exceptions.py) |
| 12 | +is a class within the [Django](/django.html) project that is thrown |
| 13 | +when there is a mistake in an application's settings. The exception |
| 14 | +can also be thrown by a developer when building a library for project |
| 15 | +that will be used with Django. |
| 16 | + |
| 17 | + |
| 18 | +## Example 1 from django-object-tools |
| 19 | +[django-object-tools](https://github.com/praekelt/django-object-tools) |
| 20 | +is a code library to make it easier to create new |
| 21 | +[Django admin](https://docs.djangoproject.com/en/dev/ref/contrib/admin/) |
| 22 | +object tools. The project's code provided as open source under the |
| 23 | +[BSD 3-Clause "New" or "Revised" License](https://github.com/praekelt/django-object-tools/blob/develop/LICENSE). |
| 24 | + |
| 25 | +[**django-object-tools / object_tools / validation.py**](https://github.com/praekelt/django-object-tools/blob/develop/object_tools/validation.py) |
| 26 | + |
| 27 | +```python |
| 28 | +from __future__ import unicode_literals |
| 29 | + |
| 30 | +~~from django.core.exceptions import ImproperlyConfigured |
| 31 | + |
| 32 | +__all__ = ['validate'] |
| 33 | + |
| 34 | + |
| 35 | +def validate(tool_class, model_class): |
| 36 | + """ |
| 37 | + Does basic ObjectTool option validation. |
| 38 | + """ |
| 39 | + if not hasattr(tool_class, 'name'): |
| 40 | +~~ raise ImproperlyConfigured("No 'name' attribute found for tool %s." % ( |
| 41 | +~~ tool_class.__name__ |
| 42 | + )) |
| 43 | + |
| 44 | + if not hasattr(tool_class, 'label'): |
| 45 | +~~ raise ImproperlyConfigured("No 'label' attribute found for tool %s." % ( |
| 46 | +~~ tool_class.__name__ |
| 47 | + )) |
| 48 | + |
| 49 | + if not hasattr(tool_class, 'view'): |
| 50 | +~~ raise NotImplementedError("No 'view' method found for tool %s." % ( |
| 51 | +~~ tool_class.__name__ |
| 52 | + )) |
| 53 | +``` |
0 commit comments