链接到Flask模板中的特定位置

问题描述

多亏了dirn的评论,我设法将其与下面的代码一起使用。

传递_anchor关键字以url_for将锚添加到生成的URL。

导航菜单:

<a href="{{ url_for('.stuff', _anchor='exactlocation') }}">Go to specific id on suff page</a>

烧瓶路线:

@main.route('/')
def stuff():
    return render_template('stuff.html')

stuff.html

...
<section id="exactlocation">
...

解决方法

在HTML中,假设有一个具有给定id的元素,我可以直接链接到页面上的特定位置:

<a href="http://www.example.com/stuff.html#exactlocation">Go there</a>

在Flask中,我尝试将锚添加到,render_template但得到了jinja2.exceptions.TemplateNotFound: stuff.html#exactlocation

@main.route('/exactlocation')
def exactlocation():
    return render_template('stuff.html#exactlocation')

如何链接到模板中的特定位置?

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...