Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add anchor to django url in template

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?

like image 301
Atma Avatar asked Sep 19 '14 19:09

Atma


People also ask

What does the built in Django template tag URL do?

A Django template is a text document or a Python string marked-up using the Django template language. Django being a powerful Batteries included framework provides convenience to rendering data in a template.

How do you hyperlink in Django?

Just use the same label {% url 'index' %} . You may use each name in urls.py to link to the url. Show activity on this post. Create a new URL in the same format and give that name instead of index.


1 Answers

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>
like image 78
Leistungsabfall Avatar answered Nov 02 '22 17:11

Leistungsabfall