由于意外的标识符,无法在Jinja2中正确使用flask变量

时间:2019-12-11 14:07:02

标签: python html flask jinja2 html-escape-characters

我正在HTML的脚本标签中执行此操作:

let reccs = '{{ratings | safe}}' 

等效于:

let reccs = '[['The Catcher in the Rye', 'The Accidental Tourist', 'Nine Stories', 'Franny and Zooey', 'The Hotel New Hampshire', "One Flew Over the Cuckoo\\'s Nest", 'The Burgess Boys', 'A Spool of Blue Thread', "Cat\\'s Eye", "L\\'élégance du hérisson", 'The Bell Jar', 'Less Than Zero', 'A Portrait of the Artist as a Young Man', 'Lolita', 'Interpreter of Maladies'], ['City of Bones', 'The Unbecoming of Mara Dyer', 'Rapture', 'Narcissus in Chains (Anita Blake, Vampire Hunter, #10)', 'Night Pleasures', 'The Reckoning', 'Lover Reborn', 'One Foot in the Grave', 'Unravel Me (Shatter Me, #2)', 'Shadow of Night', 'The Lunatic Cafe', 'Halfway to the Grave', 'Born at Midnight', 'Bloody Bones', 'Blue Moon (Anita Blake, Vampire Hunter, #8)'], ['Fifty Shades Freed', 'Mountain Interval', 'The Longest Ride', 'On Dublin Street', 'After You', 'Then Came You', 'The Tempest', 'The Bean Trees', 'A Walk to Remember', 'Nineteen Minutes', 'The Rosie Effect', 'Prodigal Summer', 'For One More Day', 'Room', 'Death of a Salesman']]';

这不让我做

{{ ratings }} 

周围没有''。

但是当我在字符串中添加''时,我得到了意外的标识符,即使我在字符串'之前使用了转义标记\!

对我来说,添加转义标签应该可以解决此问题,但仍然无法解决。

0 个答案:

没有答案