我使用命令python manage.py dumpdata > db.json从我的django应用程序中转储了一些数据
不幸的是,db.json在文件的第一行中包含一些启动日志。
该文件如下所示:
DEBUG $HOME=/home/web
DEBUG matplotlib data path /usr/local/lib/python3.5/dist-packages/matplotlib/mpl-data
DEBUG loaded rc file /usr/local/lib/python3.5/dist-packages/matplotlib/mpl-data/matplotlibrc
DEBUG matplotlib version 2.2.2
DEBUG interactive is False
DEBUG platform is linux
[{ ... then the json file ... }]我猜它来自我的日志配置,但我不能弄明白。
下面是我在setting.py中的日志配置
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
},
},
'formatters': {
'verbose': {
'format': '%(asctime)s %(levelname)s [%(module)s:%(funcName)s:%(lineno)d] %(message)s',
},
'simple': {
'format': '%(levelname)s %(message)s',
},
},
'handlers': {
'console_simple': {
'class': 'logging.StreamHandler',
'filters': ['require_debug_true'],
'formatter': 'simple',
'level': 'DEBUG',
},
'console_verbose': {
'class': 'logging.StreamHandler',
'filters': ['require_debug_false'],
'formatter': 'verbose',
'level': 'INFO',
},
},
'loggers': {
'django.request': {
'handlers': ['console_simple', 'console_verbose'],
'level': 'ERROR',
'propagate': False,
},
},
'root': {
'handlers': ['console_simple', 'console_verbose'],
'level': 'DEBUG',
},
}有什么想法吗?
发布于 2019-01-12 20:25:50
这是因为您将命令的所有输出重定向到您的文件。Django的dumpdata命令还使用一个输出参数来存储生成的文件:https://docs.djangoproject.com/en/2.1/ref/django-admin/#cmdoption-dumpdata-output
基本上,使用--output file.json而不是> file.json。
https://stackoverflow.com/questions/54159535
复制相似问题