AssertionError - 没有提供异常 - django

时间:2014-01-26 12:25:19

标签: python django python-2.7

我真的很困惑,不知道它想要什么。

这是我的简单功能

def confirm_abo(request):
  try:
      abo = Abonnement.objects.get(id=int(request.GET.get('abocid')))
      abo.status = 1
      abo.save()
      link = "http://127.0.0.1:8000/delete_link/?abocid=" + str(abo.id)
      subject = "test subject"
      message = "test message" + link
      send_mail(subject, message, 'info@test.com', [abo.email], fail_silently=False)
      return render(request,'abo_confirm.html',{'abo':abo,'abo_success':'yes'})
  except: 
      return render(request,'abo_confirm.html',{'abo_success':''})#<-- problem

我正在进入最后一行

AssertionError at /confirm_abo/ No exception supplied

错误。

我在django1.4和python 2.7中。它一直工作到现在没有任何问题..

我在做错了什么?

1 个答案:

答案 0 :(得分:21)

检查模板abc_confirm.html是否包含无效的标记用法,如下所示:

{% if x == '0' %}
...
{% else if x == '1' %}   {# used `else if` instead of `elif` %}
...
{% endif %}

可能导致AssertionError ..:

>>> from django.template import Template, Context
>>>
>>> t = Template('''
... {% if x == '0' %}
...              ..
... {% else if x == '1' %}
...              ..
... {% endif %}
... ''')
Traceback (most recent call last):
  File "<console>", line 7, in <module>
  File "/home/falsetru/.virtualenvs/django14/local/lib/python2.7/site-packages/django/template/base.py", line 125, in __init__
    self.nodelist = compile_string(template_string, origin)
  File "/home/falsetru/.virtualenvs/django14/local/lib/python2.7/site-packages/django/template/base.py", line 153, in compile_string
    return parser.parse()
  File "/home/falsetru/.virtualenvs/django14/local/lib/python2.7/site-packages/django/template/base.py", line 267, in parse
    compiled_result = compile_func(self, token)
  File "/home/falsetru/.virtualenvs/django14/local/lib/python2.7/site-packages/django/template/defaulttags.py", line 919, in do_if
    assert token.contents == 'endif'
AssertionError