xadmin datetime 类型报错 unsupported format characte

  • 定位到错误为xadmin.views.list.py中的
@property
def label(self):
    text = mark_safe(
        self.text) if self.allow_tags else conditional_escape(self.text)
    if force_text(text) == '':
        text = mark_safe(' ')
    for wrap in self.wraps:
         #就是下面这叫抛旳异常
         text = mark_safe(wrap % text)
    return text
  • 试了试print('<a href="/emmm/emm/2019-07-29%2010:00:00/update/">%s</a>' % '2019年7月29日 10:00'), 发现会报错
  • 修改源码
@property
def label(self):
    text = mark_safe(
        self.text) if self.allow_tags else conditional_escape(self.text)
    if force_text(text) == '':
        text = mark_safe('&nbsp;')
    for wrap in self.wraps:
        #改成下面这样
        text = mark_safe(wrap.replace('%s', '{}').format(text))
    return text
  • 奶丝
原文地址:https://www.cnblogs.com/edhg/p/11262410.html