Flask 带onload=";的TemplateSyntaxError;init()&引用;
我发现了一个如何使用ZeroClipboard将文本复制到剪贴板的方法。但是,我尝试将原始代码转换为flask,并运行到Flask 带onload=";的TemplateSyntaxError;init()&引用;,flask,jinja2,Flask,Jinja2,我发现了一个如何使用ZeroClipboard将文本复制到剪贴板的方法。但是,我尝试将原始代码转换为flask,并运行到TemplateSyntaxError:expected token'end of statement block',由于{%block body onload=“init();”%}而得到了'onload'。如何将onload=“init();”与Jinja一起使用 这是app.py @app.route("/table/", methods=["GET"]) def tab
TemplateSyntaxError:expected token'end of statement block',由于{%block body onload=“init();”%}
而得到了'onload'
。如何将onload=“init();”
与Jinja一起使用
这是app.py
@app.route("/table/", methods=["GET"])
def table():
return render_template('table.html')
下面是base2.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>flask-bootstrap example</title>
<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='bootstrap/css/bootstrap.css')}}" >
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.min.css">
<link rel="stylesheet" type="text/css" href="https://gitcdn.github.io/bootstrap-toggle/2.1.0/css/bootstrap-toggle.min.css" >
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='web.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='tooltip.css') }}">
<style>
.clip_button {
background:#063;
padding:4px;
width:100px;
}
</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ url_for('index') }}">test</a>
</div>
<!--/.navbar-header -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li id="home-url"><a href="{{ url_for('index') }}">Home</a></li>
<li id="about-url"><a href="#about">About</a></li>
<li id="contact-url"><a href="#contact">Contact</a></li>
</ul>
<!--/.navbar-nav -->
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
<div class="container">
{% block body %}{% endblock %}
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" src="{{url_for('static', filename='bootstrap/js/bootstrap.js')}}"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="https://gitcdn.github.io/bootstrap-toggle/2.1.0/js/bootstrap-toggle.min.js"></script>
<script type="text/javascript" >
$("a.my-tool-tip").tooltip();
$('.selectpicker').selectpicker();
$("#reference_select").selectpicker("refresh");
</script>
<script type="text/javascript" src="{{url_for('static', filename='ZeroClipboard/ZeroClipboard.js')}}"></script>
<script language="JavaScript">
////copy to clip
var clip = null;
function $(id) { return document.getElementById(id); }
function init()
{
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
}
function move_swf(ee)
{
copything = document.getElementById(ee.id+"_text").value;
clip.setText(copything);
if (clip.div)
{
clip.receiveEvent('mouseout', null);
clip.reposition(ee.id);
}
else{ clip.glue(ee.id); }
clip.receiveEvent('mouseover', null);
}
</script>
<script type="text/javascript">
{% block js %}{% endblock %}
</script>
</body>
</html>
烧瓶引导示例
.clip_按钮{
背景:#063;
填充:4px;
宽度:100px;
}
切换导航
{%block body%}{%endblock%}
$(“a.my-tool-tip”).tooltip();
$('.selectpicker').selectpicker();
$(“#参考_选择”)。选择器(“刷新”);
////复制到剪辑
var clip=null;
函数$(id){return document.getElementById(id);}
函数init()
{
clip=新的ZeroClipboard.Client();
clip.setHandCursor(true);
}
功能移动\u swf(ee)
{
copything=document.getElementById(ee.id+“_text”).value;
clip.setText(copything);
如果(剪辑分割)
{
clip.receiveEvent('mouseout',null);
重新定位(ee.id);
}
else{clip.glue(ee.id);}
clip.receiveEvent('mouseover',null);
}
{%block js%}{%endblock%}
以下是(table.html):
{%extends'base2.html%}
{%block body onload=“init();”%}
复制
{%endblock%}
onload
是一个HTML属性。这与金贾无关。您只需将其放在
标签上即可
<body onload="init();">
<body onload="init();">
<body {% block body_attrs %}{% endblock %}>
{% block body_attrs %} onload="init();" {% endblock %}