python Flask Triangle中的语法错误 [英] Syntax Error in python Flask Triangle

查看:186
本文介绍了python Flask Triangle中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我希望将AngularJS与Flask结合使用,所以我寻找了一个很好的工具来处理这些框架,因为Jinja和Angular会有彼此的问题。我发现三角形这是非常酷,工作,但刚刚达到一定点。像这样的东西的作品,例如:

 < a ng-show =post.linkhref ={{post。链路|角}}> 
{{post.title | angular}}
< / a>

但是另一方面,这是行不通的:

 < span> 
< a href =#/ posts / {{$ index | angular}}>评论< / a>
< / span>

当我尝试这样做时,我收到以下错误:


jinja2.exceptions.TemplateSyntaxError

TemplateSyntaxError:意外的字符'$'at 875


我做错了什么,或者只是在这种情况下,框架是有限的吗?帮助非常感谢。

解决方案

正如错误信息所示, $ 不能在 Jinja作为变量的一部分中使用。



相反,您需要更改Angular的分隔符


  var app = angular.module('Application',[]); 
$ b app.config(['$ interpolateProvider',function($ interpolateProvider){
$ interpolateProvider.startSymbol('{a');
$ interpolateProvider.endSymbol('a }');
}]);

无论选择什么开始和结束符号,都将作为新的分隔符。在这种情况下,您可以使用{a some_variable a}来表示一个变量> Angular。



Since I wanted to use AngularJS in combination with Flask, I searched for a cool tool to handle these frameworks properly since Jinja and Angular would have problems with each other. I found Triangle which is pretty cool and working but just up to a certain point. Stuff like this works for example:

<a ng-show="post.link" href="{{post.link|angular}}">
    {{post.title|angular}}
</a>

But on the other hand this does not work:

<span>
    <a href="#/posts/{{$index|angular}}">Comments</a>
</span>

When I try to do that, I receive following error

jinja2.exceptions.TemplateSyntaxError

TemplateSyntaxError: unexpected char u'$' at 875

Am I doing something wrong or is the framework just limited in that case? Help is highly appreciated.

解决方案

As the error message is saying, $ cannot be used in Jinja as part of a variable.

Instead, you'll need to change Angular's delimiter notation:

var app = angular.module('Application', []);

app.config(['$interpolateProvider', function($interpolateProvider) {
  $interpolateProvider.startSymbol('{a');
  $interpolateProvider.endSymbol('a}');
}]);

Whatever is chosen for the start and end symbols will act as the new delimiters. In this case, you would express a variable > to Angular using {a some_variable a}.

这篇关于python Flask Triangle中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆