how to add anchor to django url in template

2019-04-04 13:14发布

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>

This does not work.

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

2条回答
戒情不戒烟
2楼-- · 2019-04-04 14:04

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>

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

<a data-hover="Are You At Risk?" href="{% url 'home' %}/#container">My link</a>
查看更多
何必那么认真
3楼-- · 2019-04-04 14:21

past it between your anchor tag:

<a href="{% url 'your_url_name' object.parameter %}" class="pull-right" > Anchor Text{{object.parameter}}</a>
查看更多
登录 后发表回答