1
在HTML我可以直接链接到一个特定位置的页面上,假设有给定id的元素:我试图添加锚链接到一个特定的位置,在烧瓶模板
<a href="http://www.example.com/stuff.html#exactlocation">Go there</a>
在瓶到render_template
但我得到jinja2.exceptions.TemplateNotFound: stuff.html#exactlocation
。
@main.route('/exactlocation')
def exactlocation():
return render_template('stuff.html#exactlocation')
如何链接到模板中的特定位置?
这是浏览器的行为。只要正常渲染你的模板,浏览器就会处理它(假设你在页面上有指定的锚点)。 – dirn
@dirn我不确定你的意思。如果我使用return render_template('stuff.html'),浏览器如何知道去页面上的特定位置而不是顶部,请在页面加载时运行javascript检查? –
浏览器将自动跳到已命名的锚点,不需要JavaScript。唯一的要求是HTML中存在已命名的锚(即'')。 – dirn