如何在模板中将锚点添加到 django url [英] how to add anchor to django url in template

查看:26
本文介绍了如何在模板中将锚点添加到 django url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 django 模板中向我的 url 添加一个锚点,如下所示:

I am trying to add an anchor to my url in a django template like this:

<a data-hover="Are You At Risk?" href="{% url 'home' %}#container">My link</a>

这不起作用.

如何在单击此链接时将其移动到锚点?

How can I get this to move to the anchor point when this link is clicked?

推荐答案

确保实际的锚在你的模板中是这样定义的:

Make sure the actual anchor is defined like this in your template:

<a name="container"></a>

然后按照您的方式链接到它:

And then link to it the way you did:

<a data-hover="Are You At Risk?" href="{% url 'home' %}#container">My link</a>

如果这不起作用,请在 #-tag 之前添加 /:

If this does not work add / just before your #-tag:

<a data-hover="Are You At Risk?" href="{% url 'home' %}/#container">My link</a>

这篇关于如何在模板中将锚点添加到 django url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆