【发布时间】:2011-07-25 06:32:20
【问题描述】:
我想编辑 django runserver 的输出...我想现在添加对象地址,例如 apps.views.index
在此请求中添加所有查询
如何更改此设置的代码?
【问题讨论】:
我想编辑 django runserver 的输出...我想现在添加对象地址,例如 apps.views.index
在此请求中添加所有查询
如何更改此设置的代码?
【问题讨论】:
我不建议修改 runserver 命令,但是...
django-devserver 替换了manage.py runserver 命令,允许扩展输出以显示您感兴趣的任何信息。
上面链接页面上的说明显示了如何安装,底部附近有一个“构建模块”,显示了扩展输出的示例。
我不确定您要输出什么,但可能类似于:
from devserver.modules import DevServerModule
class ViewNameModule(DevServerModule):
logger_name = 'view name module'
def process_view(self, request, view_func, view_args, view_kwargs):
self.logger.info('View name: %s' % '.'.join([view_func.__module__, view_func.func_name]))
【讨论】:
我认为最好的方法是使用日志记录并为此添加一些代码
喜欢
from django.db import connection
sql=connection.queries
和
doc = {
'record_hash': hash,
'level': record.level,
'channel': record.channel or u'',
'location': u'%s:%d' % (record.filename, record.lineno),
"message": record.msg,
'module': record.module or u'<unknown>',
'occurrence_count': 0,
'solved': False,
'app_id': app_id,
'sql': sql,
}
【讨论】:
不是您问题的确切答案,但我认为django-debug-toolbar 显示了所有查询和许多其他有用信息。
【讨论】: