TypeError:

时间:2018-04-03 06:38:23

标签: python django python-3.x

我有以下代码:

    for match in tag_re.finditer(self.template_string):
        start, end = match.span()

生成以下错误:

...
  File "/Users/vng/.virtualenvs/prometheus/lib/python3.6/site-packages/django/template/base.py", line 191, in compile_nodelist
    tokens = lexer.tokenize()
  File "/Users/vng/.virtualenvs/prometheus/lib/python3.6/site-packages/django/template/base.py", line 399, in tokenize
    for match in tag_re.finditer(self.template_string):
TypeError: expected string or bytes-like object

对此错误感到好奇,我补充道:

    print(type(self.template_string))
    for match in tag_re.finditer(self.template_string):

结果如下:

<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'django.utils.functional.lazy.<locals>.__proxy__'>
Internal Server Error: /workflow/archive/
Traceback (most recent call last):
...
    tokens = lexer.tokenize()
  File "/Users/vng/.virtualenvs/prometheus/lib/python3.6/site-packages/django/template/base.py", line 399, in tokenize
    for match in tag_re.finditer(self.template_string):
TypeError: expected string or bytes-like object
<class 'str'>

然后我尝试做补丁:

    self.template_string = str(self.template_string)
    for match in tag_re.finditer(self.template_string):

错误消失了。

为什么在该特定时间点评估不是django.utils.functional.lazy.<locals>.__proxy__'字符串?

0 个答案:

没有答案