Warm tip: This article is reproduced from serverfault.com, please click

flask-如何使用jinja / html处理引号中的引号?

(flask - How to handle quotes in quotes in quotes with jinja/html?)

发布于 2020-09-25 13:18:03

我可以找到许多有关世界语引号的帖子,以便在页面上显示它们,但就我而言,我想

               <button onclick="window.location.href='{{ url_for("admin.pairs(entry.id)") }}';">
                   PP
               </button>                    

因此,onclick之后是需要用引号引起来的内容,并且在我内部有href,其后是需要用引号引起来的其他内容,其后是url_for,其中包含需要用引号引起来的内容。因此,我尝试在单引号和双引号之间切换,例如:“'”“'”,但是它不起作用。因此,在这种情况下,哪些引号需要转义?还是关于别的东西?

Questioner
Alma
Viewed
0
Simeon Nedkov 2020-09-25 21:33:21

一种方法是将的结果存储url_for在变量中,并使用它而不是调用url_for

{% set url = url_for("admin.pairs(entry.id)") %}

<button onclick="window.location.href='{{ url }}';">PP</button>