我的烧瓶应用程序启动时会渲染renders_template index.html
@app.route('/index')
def index():
user = {'username' : 'Pinto'}
bios = []
return render_template('index.html', title='JAF', user=user, bios=bios)
index.html的头部链接有static / css / style.css,并且CSS在初始render_tempate加载。但是,当使用jquery将jinja2模板加载到index.html时,我会丢失所有样式。
main.js
$("#click_render").click(function() {
$("html").load("/click_render");
})
routes.py(数据替换为占位符)
@app.route('/click_render')
def click_render():
user = {'username' : 'Pinto'}
bios = [
{dataset1},
{dataset2},
{dataset3},
]
return render_template('index.html', title='JAF', user=user, bios=bios)
index.html(head.html加载CSS,在将head移到模板之前,我也遇到了同样的问题)
<html>
<head>
{% include 'head.html' %}
</head>
<body style='margin:0'>
<button type="button" id='click_render'>route/click_render</button>
<h1>Hello, {{ user.username }}!</h1>
<div class="included">
{% include 'included.html' %}
</div>
</body>
</html>
included.html
{% for bio in bios %}
<div>
<p>{{ bio.name }} </p>
<p>{{ bio.age }} </p>
<p>{{ bio.height }}</p>
</div>
{% endfor %}
我的浏览器确实收到以下错误:
jquery.min.js:4 [不推荐使用]不赞成在主线程上使用同步XMLHttpRequest,因为它对最终用户的体验有不利影响。如需更多帮助,请检查https://xhr.spec.whatwg.org/。