Django:ValueError:无法配置处理程序 - [Errno 2]

时间:2016-08-23 12:49:59

标签: python django pycharm

我是Python和Django的新手,目前正忙着通过www.djangoproject.com上的教程学习自己。我正在使用PyCharm并在OS X El Capitan上工作。我从GitHub导入了一个项目,并为基于Python 3.5.1的项目解释器创建了一个虚拟环境。在vm我安装了django。

然后我激活了vm。

现在..我开始尝试在终端中执行简单命令,如python manage.py startapp deonapppython manage.py runserver,但每次我收到错误,我粘贴在下面..我错过了什么?我似乎无法找到/ log /目录?

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 558, in configure
    handler = self.configure_handler(handlers[name])
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 731, in configure_handler
    result = factory(**kwargs)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1008, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1037, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/utils/log.py", line 75, in configure_logging
    logging_config_func(logging_settings)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 795, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 566, in configure
    '%r: %s' % (name, e))
ValueError: Unable to configure handler 'file': [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'

4 个答案:

答案 0 :(得分:2)

我设法解决了这个问题。未创建日志目录,因为它已在.gitignore文件中排除。我完全忘了看看被排除在外的东西:)。我手动创建了目录,现在它传递了错误。 出温

答案 1 :(得分:0)

您可以将其添加到setting.py

LOG_PATH = os.path.join(BASE_DIR, 'log')

if not os.path.join(LOG_PATH):
    os.mkdir(LOG_PATH)

答案 2 :(得分:0)

在大多数情况下,其他答案也可能是正确的,但是在我的情况下,日志目录已创建,但是日志目录对我的用户具有权限问题。只需对我的用户使用chown(我的案例www-data)即可解决问题。

(以我为例):

sudo chown www-data:www-data /var/log/django/

使用username:user-group代替www-data:www-data,并使用日志目录代替/var/log/django/

答案 3 :(得分:0)

Traceback说,它不是“ log”目录。

  1. 在路径log中创建名称为/Users/deon/Documents/PyCharmProjects/Developments/deonproject/的目录
  2. 创建空文件.gitkeep
  3. 创建.gitkeep文件后,将其推送到GitHub