Как создать новую константу для сообщений Django?
Я хочу добавить новую константу messages.NOTICE в дополнение к существующим шести константам. Его я могу использовать для отображения уведомлений с помощью Bootstrap CSS.
# settings.py
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
messages.DEBUG: 'alert-secondary',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
#messages.NOTICE: 'alert-primary', #To add
}
Ошибка при попытке добавить вышеуказанное.
G:\runtime\devui\devui\settings.py changed, reloading.
Traceback (most recent call last):
File "G:\runtime\devui\manage.py", line 22, in
main()
File "G:\runtime\devui\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\devuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\devuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 382, in execute
settings.INSTALLED_APPS
File "C:\Users\devuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf\__init__.py", line 89, in __getattr__
self._setup(name)
File "C:\Users\devuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf\__init__.py", line 76, in _setup
self._wrapped = Settings(settings_module)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\devuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf\__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\devuser\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "G:\runtime\devui\devui\settings.py", line 44, in
messages.NOTICE: 'alert-primary',
^^^^^^^^^^^^^^^
AttributeError: module 'django.contrib.messages.constants' has no attribute 'NOTICE'
PS G:\runtime\devui>
Подробнее здесь: https://stackoverflow.com/questions/786 ... ges-notice
Django django.contrib.messages добавляет новые постоянные сообщения. ВНИМАНИЕ ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Django django.contrib.messages добавляет новые постоянные сообщения. ВНИМАНИЕ
Anonymous » » в форуме Python - 0 Ответы
- 22 Просмотры
-
Последнее сообщение Anonymous
-