请帮助解决以下问题。
ValueError: Unable to configure filter 'special': Cannot resolve 'project.logging.SpecialFilter': No module named project
由于
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 80, in _configure_logging
logging_config_func(self.LOGGING)
File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python2.7/logging/config.py", line 562, in configure
'filter %r: %s' % (name, e))
ValueError: Unable to configure filter 'special': Cannot resolve 'project.logging.SpecialFilter': No module named project
ubuntu@ip-172-31-10-91:/data/apache/serve/web-app/datagatheringwebapp$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 80, in _configure_logging
logging_config_func(self.LOGGING)
File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python2.7/logging/config.py", line 562, in configure
'filter %r: %s' % (name, e))
ValueError: Unable to configure filter 'special': Cannot resolve 'project.logging.SpecialFilter': No module named project
答案 0 :(得分:0)
您收到错误消息是因为'project.logging.SpecialFilter'不存在,您必须在Django项目中创建此类/方法。
在/目录中创建模块'mylogging.py',其中包含settings.py和wsgi.py和url.py。 一个示例SpecialFilter实现:-
import logging
from random import choice
class SpecialFilter(logging.Filter):
# """
# This is a filter which injects contextual information into the log.
#
# Rather than use actual contextual information, we just use random
# data in this demo.
# """
USERS = ['jim', 'fred', 'sheila']
IPS = ['123.231.231.123', '127.0.0.1', '192.168.0.1']
def filter(self, record):
record.ip = choice(SpecialFilter.IPS)
record.user = choice(SpecialFilter.USERS)
return True
还修复您的setting.py以正确指向新的SpecialFilter模块位置。
'filters': {
'special': {
'()': '<your_project_name>.mylogging.SpecialFilter',
# '()': 'django.utils.log.RequireDebugTrue',
# 'foo': 'bar',
},