Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: button link

I am a novice Django user trying to create a push button, which links to another page in my site when clicked. I've tried a few different examples which I've found, but none seem to be working for me...

As an example, why is this not working?

<form method="link" action="{% url 'gui' %}">
<input type="button" value="Start">
</form>

Here, 'gui' is the name I have given to my link in urls.py to the desired page.

I am also fairly new to HTML in general, so it may be my HTML that is wrong...

Thank you.

like image 409
Karnivaurus Avatar asked Feb 20 '14 18:02

Karnivaurus


2 Answers

Is there any particular reason you're using both a form and a button?

Can you use an a (anchor tag)?

<a href="{% url 'appname.nameOfFunctionInViews' %}">Click here</a>

If you want to use a form, please post your urls.py.

like image 53
Silwest Avatar answered Oct 25 '22 11:10

Silwest


To create a button that can be clicked and redirect to another link, you can wrap <button></button> around <a></a>, which worked for me:

<button type="button">
    <a href="{% url 'name_of_your_view' %}">Click here!</a>
</button>
like image 28
Yi Zong Kuang Avatar answered Oct 25 '22 11:10

Yi Zong Kuang