0

这是一个时间紧迫的错误,否则我不会在这里发布,这也是我第一次尝试使用 django 和 python,所以请相应地考虑。

我收到错误

%o format: a number is required, not str

在我的 django 应用程序中。它显示错误的地方:(我正在尝试创建一个消息字符串)

msg_donor = 'Dear %s,\nThank you for contributing to %s \'s fundraising campaign 
on Milaap.org. You\'ve made our day.\nRemember, since this is a loan, and not 
donation, 100% of your money will come back to you!\nYou will shortly receive 
your milaap login details. You can check who your money has gone to and track 
your repayments through your account. Be sure to sign up and check your account
regularly for updates.\n\n%s' % (d.name, c.fundraiser_name, regardsStr)

我没有在我的应用程序中写任何 %o 并且我想知道这个错误是如何产生的?

4

2 回答 2

1

你有100% of your money你的字符串。%是一个格式化字符。用于100%% of your money在其中放置文字%

(我有点惊讶 Python 跳过了 and 之间的空格%o但无论如何。)

于 2012-02-26T06:17:41.380 回答
0

问题是由%您的字符串中的一个杂散引起的: 100%

当您进行字符串格式化时,您必须确保通过执行转义文字 %%%

试试这个:

msg_donor = """Dear %s,\nThank you for contributing to %s's fundraising campaign 
on Milaap.org. You've made our day.\nRemember, since this is a loan, and not 
donation, 100%% of your money will come back to you!\nYou will shortly receive 
your milaap login details. You can check who your money has gone to and track 
your repayments through your account. Be sure to sign up and check your account
regularly for updates.\n\n%s""" % (d.name, c.fundraiser_name, regardsStr)
于 2012-02-26T06:18:12.540 回答