join函数好像有问题

来源:9-1 viewmodel意义的体现与filter函数的巧妙应用

china震震

2018-04-14

错误提示:

Traceback (most recent call last):

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1997, in __call__

    return self.wsgi_app(environ, start_response)

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1985, in wsgi_app

    response = self.handle_exception(e)

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1540, in handle_exception

    reraise(exc_type, exc_value, tb)

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\_compat.py", line 33, in reraise

    raise value

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1982, in wsgi_app

    response = self.full_dispatch_request()

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request

    rv = self.handle_user_exception(e)

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1517, in handle_user_exception

    reraise(exc_type, exc_value, tb)

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\_compat.py", line 33, in reraise

    raise value

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request

    rv = self.dispatch_request()

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\app.py", line 1598, in dispatch_request

    return self.view_functions[rule.endpoint](**req.view_args)

  File "F:\O-BOOK\O-BOOK\app\web\book.py", line 42, in search

    return render_template('search_result.html', books=books)

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\templating.py", line 134, in render_template

    context, ctx.app)

  File "F:\flasklearn\blog\venv\lib\site-packages\flask\templating.py", line 116, in _render

    rv = template.render(context)

  File "F:\flasklearn\blog\venv\lib\site-packages\jinja2\asyncsupport.py", line 76, in render

    return original_render(self, *args, **kwargs)

  File "F:\flasklearn\blog\venv\lib\site-packages\jinja2\environment.py", line 1008, in render

    return self.environment.handle_exception(exc_info, True)

  File "F:\flasklearn\blog\venv\lib\site-packages\jinja2\environment.py", line 780, in handle_exception

    reraise(exc_type, exc_value, tb)

  File "F:\flasklearn\blog\venv\lib\site-packages\jinja2\_compat.py", line 37, in reraise

    raise value.with_traceback(tb)

  File "F:\O-BOOK\O-BOOK\app\templates\search_result.html", line 1, in top-level template code

    {% extends "base.html" %}

  File "F:\O-BOOK\O-BOOK\app\templates\base.html", line 97, in top-level template code

    {% block content %} {% endblock %}

  File "F:\O-BOOK\O-BOOK\app\templates\search_result.html", line 28, in block "content"

    <span>{{book.intro}}</span>

  File "F:\flasklearn\blog\venv\lib\site-packages\jinja2\environment.py", line 430, in getattr

    return getattr(obj, attribute)

  File "F:\O-BOOK\O-BOOK\app\view_models\book.py", line 17, in intro

    return ' / '.join(intros)

TypeError: sequence item 0: expected str instance, tuple found

具体代码:

@property
def intro(self):
   intros = filter(lambda x:True if x else False,
                   [self.author,self.publisher,self.price])
   return ' / '.join(intros)

写回答

1回答

7七月

2018-04-15

你这里 在调用join的时候就报错了吗?应该不是join的问题。感觉是模板报的错误。

0
0

Python Flask高级编程之从0到1开发《鱼书》精品项目

7月老师深入浅出剖析Flask核心机制,和你一起探讨Python高级编程

2735 学习 · 1267 问题

查看课程