how to add anchor to django url in template

Atma picture Atma · Sep 19, 2014 · Viewed 12.3k times · Source

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?

Answer

Leistungsabfall picture Leistungsabfall · Sep 19, 2014

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>