对于在Django/Python中实现的网站,我们有以下要求:
在视图页面上,每个Web分页显示15条消息.如果来自同一来源的更多两条或更多条消息在视图上相互跟随,则应将它们组合在一起.
也许不清楚,但以下例子可能是:
一个例子是(这次在页面上有5条消息):
Message1 Source1
Message2 Source2
Message3 Source2
Message4 Source1
Message5 Source3
...
Run Code Online (Sandbox Code Playgroud)
这应显示为:
Message1 Source1
Message2 Source2 (click here to 1 more message from Source2)
Message4 Source1
Message5 Source3
Message6 Source2
Run Code Online (Sandbox Code Playgroud)
因此,在每个页面上,页面上会显示固定数量的项目,其中一些项目已重新分组.
我们想知道如何创建Django或MySQL查询以便以最佳和简单的方式查询这些数据.请注意,使用分页并且消息按时间排序.
PS:由于SQL的性质,我认为没有一个简单的解决方案,但有时复杂的问题很容易解决
我们有一个令人讨厌的问题,我们看到python日志记录模块在我们的服务器上运行mod_python时表现不同.在shell中执行相同的代码,或者使用runserver命令或使用mod_wsgi在django中执行相同的代码时,行为是正确的:
import logging
logger = logging.getLogger('site-errors')
logging.debug('logger=%s' % (logger.__dict__))
logging.debug('logger.parent=%s' % (logger.parent.__dict__))
logger.error('some message that is not logged.')
Run Code Online (Sandbox Code Playgroud)
然后我们进行以下记录:
2009-05-28 10:36:43,440,DEBUG,error_middleware.py:31,[logger = {'name':'site-errors','parent':<logging.RootLogger instance at 0x85f8aac>,'handlers': [],'level':0,'禁用':0,'manager':<logging.Manager实例位于0x85f8aec>,'propagate':1,'filters':[]}]
2009-05-28 10:36:43,440,DEBUG,error_middleware.py:32,[logger.parent = {'name':'root','parent':None,'handlers':[<logging.StreamHandler instance at at 0x8ec612c>,<logging.handlers.RotatingFileHandler实例位于0x8ec616c>],'level':10,'禁用':0,'传播':1,'过滤器':[]}]
可以看出,没有为子记录器"site-errors"设置处理程序或级别.
日志配置在settings.py中完成:
MONITOR_LOGGING_CONFIG = ROOT + 'error_monitor_logging.conf'
import logging
import logging.config
logging.config.fileConfig(MONITOR_LOGGING_CONFIG)
if CONFIG == CONFIG_DEV:
DB_LOGLEVEL = logging.INFO
else:
DB_LOGLEVEL = logging.WARNING
Run Code Online (Sandbox Code Playgroud)
第二个问题是我们还在__init__.py中添加了一个自定义处理程序,该处理程序将其作为error_middleware.py驻留在该文件夹中:
import logging
from django.conf import settings
from db_log_handler import DBLogHandler
handler = DBLogHandler()
handler.setLevel(settings.DB_LOGLEVEL)
logging.root.addHandler(handler)
Run Code Online (Sandbox Code Playgroud)
在日志记录中无法看到自定义处理程序!
如果有人知道问题所在,请告诉我们!不要犹豫要求提供额外的信息.这肯定有助于解决问题.