在python / jinga2后端发送的插值字符串上获取无效标记

问题描述 投票:1回答:1

我将一个名为apiID的变量从tornado / jinja2 python文件发送到我的vuejs模板,如下所示:

class SmartAPIUIHandler(BaseHandler):
    def get(self, yourApiID):
        doc_file = "smartapi-ui.html"
        dashboard_template = templateEnv.get_template(doc_file)
        dashboard_output = dashboard_template.render(apiID = yourApiID )
        self.write(dashboard_output)

然后在vuejs我插入变量没有问题,除了它给我一个错误enter image description here

它说:未捕获的SyntaxError:无效或意外的令牌

我检查了python处理程序文件,apipID是一个字符串,所以我没有看到问题。我对python很新,所以对你们中的一个人来说答案可能更明显。我很感激帮助!!

vue.js jinja2 interpolation
1个回答
1
投票

因为dashboard_output = dashboard_template.render(apiID = yourApiID ),你必须在你的模板中有一些代码:

this.apiID = {{ apiID }};

由于值不是数字而是字符串,请添加's:

this.apiID = '{{ apiID }}';
© www.soinside.com 2019 - 2024. All rights reserved.