I created a link in my polls application of Django and it looks like my Button links doesn't work. What is the mistake I am doing here?
My urls.py is
from django.conf.urls import url
from . import views
app_name = 'polls'
urlpatterns = [
# ex: /polls/
#url(r'^$', views.index, name='index'),
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^login/$', views.LoginView.as_view(), name='login'),
# ex: /polls/5/
# the 'name' value as called by the {$ url $} template tag
#url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
# ex: /polls/5/results/
#url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
# ex: /polls/5/vote/
url(r'^(?P<ballot_id>[0-9]+)/vote/$', views.vote, name='vote'),
]
And I create buttons and links like this
<button type="submit" class="btn btn-primary"><a href="{% url 'polls:index' %}"></a>
{% bootstrap_icon "home" %}
</button>
<button type="submit" class="btn btn-primary"><a href="{% url 'polls:login' %}"></a>
{% bootstrap_icon "user" %} User Login
</button>
There are 2 solutions to this:
Either place the <a> outside of the <button>, like this:
<a href="{% url 'polls:index' %}">
<button class="btn btn-primary">{% bootstrap_icon "home" %}</button>
</a>
or leave only the <a> (and remove the <button>), like this:
<a href="{% url 'polls:index' %}" class="btn btn-primary">{% bootstrap_icon "home" %}</a>