Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1K
Views
Django: Bootstrap button link doesn't work

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>

In inspector it looks like enter image description here

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!