How to use a button to point to an existing url

Viewed 76

I'm new to django, here i've to point a button to an existing url

<form> <input type="button" value="Put Your Text Here" onclick="window.location.href='/polls/{{ question.id }}/results/'" />
</form>

here i've created a button that points to a perticular url. is there any oprtimized methods available?

2 Answers

You can make use of the {% url … %} template tag [Django-doc]:

<li>
    <a href="{% url 'detail' question_id=question.pk">
        {{ question.question_text }}</a></li>
        <button type='submit'> Result
        </button>
    </a>
</li>
<li><a href="/polls/{{ question.question_id }}/">{{ question.question_text }}</a></li><a href="/polls/{{ question.question_id }}/results/" title="{{ question }} Results"><button type='submit'> Result</button></a>
Related