link div 在 url 的另一个页面中带有锚标记 Django

link a div in another page in url with an anchor tag Django

我正在尝试使用锚标记访问另一个页面中的 div 和 Django 中的 url。

这里是html,

<a href="{% url 'anotherpage#show' %}>click here </a>

在另一页中,

<div id="show">link to this div </div>

如何使用 url 访问 show div?

您需要先link到页面。然后 link 到 Anchor

## assume this will take you to the main page. 
<a href="{% url 'anotherpage' %}>Page URL</a>

那么你所要做的就是在url标签之后添加需要的锚点。

<a href="{% url 'anotherpage' %}#show">Page URL to show directly. </a>

希望对您有所帮助。