Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to avoid that Django adds url link to every html element that follows the link

i would like to achieve something very basic in Django but can’t find out what I am doing wrong. On my apps "index.html", I would like to add a button which redirects to another html template ("site.html") with other content. I added the following to "index.html" which is working:

<body>
<h2>foo</h2>
    {% block content %}
    <button><a href="{% url 'site' %}"/>Click</button>
    {% endblock %}
<p>bar</p>
</body>

Clicking on the button gets me to "site.html", however all html items which I add on "index.html", for example the paragraph "bar" would also get rendered as hyperlink.
I tried creating different Django blocks or making different html sections but that doesn’t fix it.

Thank you for your help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re missing a closing anchor </a> tag after your element.

<body>
<h2>foo</h2>
    {% block content %}
    <button><a href="{% url 'site' %}">Click</a></button>
    {% endblock %}
<p>bar</p>
</body>

I will note that I’m not sure it’s "correct" to have an anchor tag within a button. I think you’re better off styling your anchor tag to appear as a button.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading