How to add anchor to django url in template

I am trying to add a binding to my url in a django template as follows:

<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 I click this link?

+7
django django-templates django-urls anchor
source share
2 answers

Verify that the actual anchor is defined in the template as follows:

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

And then refer to it the way you did it:

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

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

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

past it between your anchor tag:

 <a href="{% url 'your_url_name' object.parameter %}" class="pull-right" > Anchor Text{{object.parameter}}</a> 
0
source share

All Articles