gpt4 book ai didi

python - 收到 'got multiple values for keyword argument' 错误

转载 作者:行者123 更新时间:2023-11-30 23:30:04 24 4
gpt4 key购买 nike

因此,我将生成一份为期两周的过期域名报告。它每天都会通过电子邮件发送。几天来我一直在努力解决我遇到的一个特定问题,但我一生都无法弄清楚为什么会发生这种情况。错误是“email_report() 获得关键字参数“持续时间”的多个值”。这是代码(我知道它很难看)..

这是我的网址:

url(r'^reports/domains/(?P<duration>\d+)(?P<unit>\w)/emailreport/$', email_report),

这是我的逻辑和观点:

def expiring_domains_logic(unit):
report_date = date.today()
unit = unit.lower()
if unit == 'd': report_date = report_date + timedelta(days = int(duration))
elif unit == 'w': report_date = report_date + timedelta(weeks = int(duration))
elif unit == 'm': report_date = report_date + timedelta(weeks = int(duration)*4)
elif unit == 'y': report_date = report_date + timedelta(weeks = int(duration)*52)

domains = DomainMain.objects.filter(nextrenewaldate__lte = report_date).order_by('registrarmultiid')
cost = count_cost(domains)
registrars = Registrars.objects.all()
return (domains, report_date, cost, registrars)

def expiring_domains(request = None, duration = 2, unit = 'w'):
(domains, report_date, cost, registrars) = expiring_domains_logic(unit)
if request == None:
return render_to_string('reports/expiring_domains.html', { 'domains': domains, 'expiration_date': report_date, 'cost': cost, 'registrars': registrars })
else:
return render(request, 'reports/expiring_domains.html', { 'domains': domains, 'expiration_date': report_date, 'cost': cost, 'registrars': registrars })

def email_report(duration, unit):
domains = expiring_domains(duration, unit) # two weeks
email_targets = Owners.objects.filter(emailflag = 'Y')
email_targets = (x.coemail for x in email_targets)
email_body = domains.content # This is where we put together the email body
msg = mail.EmailMessage('subject_here', email_body, 'no-reply@[omitted]', email_targets)
msg.content_subtype = "html"
msg.send()

回溯:

File "/home/ashley/enviro/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
Exception Type: TypeError at /reports/domains/2w/emailreport/
Exception Value: email_report() got multiple values for keyword argument 'duration'

最佳答案

您的 URL 将 email_report 定义为 View ,但这实际上根本不是 View - 它不接受请求并返回响应。该 View 似乎名为 expiring_domains。

关于python - 收到 'got multiple values for keyword argument' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20864554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com