-1

尝试转换可能的整数变量时出现此错误:

for page in domain.page_set.all():
    filename = str(domain.url) + '_page_' +str(page.id())+ '.html'

错误:

  File "/Applications/djangostack-1.4.7-0/apps/django/django_projects/controls/polls/models.py", line 40, in make_config_file
    filename = str(domain.url)+"_page_"+str(page.id())+".html"
TypeError: 'long' object is not callable

这里有什么问题?“long is not callable”是什么意思?

4

1 回答 1

3

page.id是 a long,它不是函数,因此不可调用:

In [1]: id = 5586L
In [2]: type(id)
Out[2]: long
In [3]: id()
TypeError: 'long' object is not callable

尝试只是做str(page.id)

或者,您可以像这样使用 Python 的字符串格式:

for page in domain.page_set.all():
    filename = "{}_page_{}.html".format(domain.url, page.id)
于 2013-09-19T00:08:13.553 回答