链接到Flask温度中的特定位置

2024-10-01 13:43:14 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

在Flask中,我试图给render_template添加锚定,但是我得到了jinja2.exceptions.TemplateNotFound: stuff.html#exactlocation。在

^{pr2}$

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


Tags: comidhttp元素go链接examplehtml
1条回答
网友
1楼 · 发布于 2024-10-01 13:43:14

多亏了迪恩的评论,我设法用下面的代码实现了这一点。在

_anchor关键字传递给url_for以向生成的URL追加锚定。在

导航菜单:

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

烧瓶路径:

^{pr2}$

stuff.html

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

相关问题 更多 >