我正在使用templatetag從我寫的公式返回變量。我一直在試圖找出爲什麼我得到這個回溯。我已經在shell中測試了公式,並且所有工作都正常。我在標籤和視圖中做了一些打印語句。但無法弄清楚這個原因。不支持的操作數類型爲+:'int'和'unicode'
TRACEBACK:
Traceback:
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
117. response = middleware_method(request, e)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/urbanrunic/developement/levelend/levelend/levelend/configs/common/../../apps/common/utils/decorators.py" in wrapper
65. context_instance=RequestContext(request), mimetype=mimetype)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/loader.py" in render_to_string
188. return t.render(context_instance)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
123. return self._render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/loader_tags.py" in render
127. return compiled_parent._render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/loader_tags.py" in render
127. return compiled_parent._render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django_static/templatetags/django_static.py" in render
108. code = self.nodelist.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/loader_tags.py" in render
64. result = block.nodelist.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/loader_tags.py" in render
64. result = block.nodelist.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/defaulttags.py" in render
311. return self.nodelist_true.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/Users/urbanrunic/.virtualenvs/levelend/lib/python2.6/site-packages/django/template/defaulttags.py" in render
227. nodelist.append(node.render(context))
File "/Users/urbanrunic/developement/levelend/levelend/levelend/configs/common/../../apps/lender/templatetags/lender_tags.py" in render
15. context[self.min] = monthlyPayment(self.how_much, self.apr_min, self.max_repayment_length)
File "/Users/urbanrunic/developement/levelend/levelend/levelend/configs/common/../../apps/lender/utils.py" in monthlyPayment
34. M = P/((1 - 1/(1 + mi) ** n)/mi)
Exception Type: TemplateSyntaxError at /results/
Exception Value: Caught TypeError while rendering: unsupported operand type(s) for +: 'int' and 'unicode'
公式:
def monthlyPayment(P, mi, n):
""" returns monthly payment """
M = P/((1 - 1/(1 + mi) ** n)/mi)
return M
TAG:
class MinMonthlyPaymentsNode(Node):
def __init__(self, how_much, apr_min, max_repayment_length, min):
self.how_much, self.apr_min, self.max_repayment_length, self.min = how_much, apr_min, max_repayment_length, min
def render(self, context):
context[self.min] = monthlyPayment(self.how_much, self.apr_min, self.max_repayment_length)
return ''
def do_monthly_payment(parser, token):
"""
returns a monthly payment based on the formula with interst and amount of loan
Example usage:
{% min_monthly_payments how_much, apr_min, max_repayment_length as [min]%}
"""
args = token.contents.split()
if len(args) != 6:
raise TemplateSyntaxError, "min_monthly_payments tag takes exactly six arguments"
if args[4] != 'as':
raise TemplateSyntaxError, "fourth argument to the min_monthly_payments tag must be 'as'"
return MinMonthlyPaymentsNode(args[1], args[2], args[3], args[5])
register.tag('min_monthly_payments', do_monthly_payment)
中號ODELS:
class Lender(TitleAndSlugModel):
"""
A lender
"""
DISBURSED_TYPES = get_namedtuple_choices('DISBURSED_TYPES', (
(0, 'DIRECT_TO_SCHOOL', 'Directly to School'),
(1, 'SENT_TO_YOU', 'Sent to You'),
))
SUITABILITY_TYPES = get_namedtuple_choices('SUITABILITY_TYPES', (
(0, 'UNDERGRADUATE', 'Undergraduate'),
(1, 'GRADUATE', 'Graduate'),
(2, 'LAW', 'Law'),
(3, 'MEDICAL', 'Medical'),
(4, 'PARENTS', 'Parents'),
))
# Financial summary
apr_min = models.DecimalField(max_digits=5, decimal_places=2)
apr_max = models.DecimalField(max_digits=5, decimal_places=2)
# Borrower rewards
auto_debit_discount = models.DecimalField(max_digits=5, decimal_places=2)
auto_debit_discount_note = models.CharField(max_length=250, null=True, blank=True)
additional_rewards_1 = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
additional_rewards_1_note = models.CharField(max_length=250, null=True, blank=True)
additional_rewards_2 = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
additional_rewards_2_note = models.CharField(max_length=250, null=True, blank=True)
# General info
loan_name = models.CharField(max_length=250)
loan_services_by = models.CharField(max_length=250)
funds_disbursed = models.PositiveIntegerField(choices=DISBURSED_TYPES.get_choices(), default=0)
co_signer_release_available = models.IntegerField(null=True, blank=True, help_text="Please enter in months")
suitable_for = MultiSelectField(max_length=50, choices=SUITABILITY_TYPES.get_choices())
external_url = models.URLField(max_length=250)
lender_logo = FileBrowseField("Image", max_length=200, directory="uploads/", extensions=[".jpg"], blank=True, null=True)
schools = models.ManyToManyField(School)
# Repayment
max_repayment_length = models.IntegerField(null=True, blank=True, help_text="Please enter in years")
max_deferral_length = models.IntegerField(null=True, blank=True, help_text="Enter as X months after graduation")
# Rates
interest_rate_index = models.DecimalField(max_digits=5, decimal_places=2)
interest_rate_index_note = models.CharField(max_length=250, null=True, blank=True)
min_repayment_rate = models.DecimalField(max_digits=5, decimal_places=2)
min_repayment_rate_note = models.CharField(max_length=250, null=True, blank=True)
max_repayment_rate = models.DecimalField(max_digits=5, decimal_places=2)
max_repayment_rate_note = models.CharField(max_length=250, null=True, blank=True)
# Fees
origination_fee = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
guarantee_fee = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
# Notes
notes = models.TextField(null=True, blank=True)
def get_absolute_url(self):
return reverse("results_detail", args=[self.slug])
def __unicode__(self):
return "%s" % (self.title)
再次任何幫助將不勝感激,哪怕是朝着正確方向的一個點。謝謝!
如果您的問題是關於回溯,請包含回溯。 –
你可以編輯你的問題,包括實際的回溯? – SingleNegationElimination
對不起,已添加追蹤編輯。 – tjoenz