1. AttributeError: ‘XXXField’ object has no attribute ‘model’
出现情景:
在定义models.DateTimeField或者models.DateTimeField的时候,如果访问了这些属性,也许会出现AttributeError: ‘XXXField’ object has no attribute ‘model’这样的错误。
解决方法:
在定义DateTimeField后面加上(blank=True),便可以解决。
例子:
class test(models.Model):
test_time = models.DateTimeField
Exception Value:
'DateTimeField' object has no attribute 'model'
修改后:
class test(models.Model):
test_time = models.DateTimeField(blank=True)
2. TemplateSyntaxError:Exception Value: ‘for’ statements should use the format ‘for x in y’: for xxx in yyy
出现情景:在模板中使用过滤器的时候,在“|”左右或者其他的地方多加了多余的空格,也许就会出现TemplateSyntaxError。
解决方法:
删除多余的空格。
例子:
{% for x in y | list %}
...
{{ page | add: "1" }}
...
TemplateSyntaxError: 'for' statements should use the format 'for x in y': for x in y | list
修改后:
{% for x in y|list %}
...
{{ page|add:"1" }}
...