Django / Python附加参数导致内部服务器错误

时间:2017-11-28 11:01:13

标签: python django

对于getView()我有

class Notification

如果被称为

则有效
class Meta:
    db_table = "eng_notification"
    ordering = ('-created_at',)

[...]     type = models.CharField(max_length=10,
choices=TYPE_NOTIFY_CHOICES.items(), verbose_name="Type of Notification",
default='SYS')

@classmethod
def notify(cls, msg_or_mid, target, sender=None, types=['SYS'], **kargs):
    params = result = {}
    try:
        if isinstance(msg_or_mid, Message):
            msg = msg_or_mid
        else:
            msg = Message.objects.get(mid=msg_or_mid)
    except Message.DoesNotExist:
        log.debug(u'A template %s não existe na base de dados!' % msg_or_mid)
    except Exception:
        log.debug(u"Mensagem nao enviada: %s" % msg_or_mid)
    else:
        for k in kargs:
            params[k] = u"%s" % kargs[k]
        for type in types:
            n = cls()
            n.msg = msg
            n.target = target
            if sender:
                n.sender = sender
            n.type = type
            n.status = 2
            n.params = str(params) if params else "{}"
            if type == 'EMAIL':
                result[type] = n.sendEmail()
            elif type == 'SMS':
                result[type] = n.sendSMS()
            else:
                result[type] = n.sendSYS()
    return result

但如果使用额外参数Notification.notify( msg, employee_from_user(solicitante), chamado=self.chamado.cache_numero, previsao=DateUtils.date_to_str(self.previsao_fim) ) 调用internal server error会导致'SYS'

Notification.notify(
    msg,
    employee_from_user(solicitante),
    chamado=self.chamado.cache_numero,
    previsao=DateUtils.date_to_str(self.previsao_fim),
    'SYS'
)

由于我是新手,我完全迷失了。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

'SYS'中的Notification.notify()是位置参数,通知方法不接受。添加*args(并在命名参数之前移动' SYS')

def notify(cls, msg_or_mid, target, sender=None, types=['SYS'], *args, **kargs):

或添加名称

Notification.notify(
    msg,
    employee_from_user(solicitante),
    chamado=self.chamado.cache_numero,
    previsao=DateUtils.date_to_str(self.previsao_fim),
    something='SYS' # now it will be in kwargs
)
相关问题