Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1K
Visualizações
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

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda