我在Django的民意调查应用程序中创建了一个链接,看起来我的Button链接不起作用。我在这里做的错误是什么?
我的urls.py是
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'),
]
我创建了这样的按钮和链接
<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>
答案 0 :(得分:3)
有两种解决方案:
将<a>
置于<button>
之外,如下所示:
<a href="{% url 'polls:index' %}">
<button class="btn btn-primary">{% bootstrap_icon "home" %}</button>
</a>
或仅保留<a>
(并删除<button>
),如下所示:
<a href="{% url 'polls:index' %}" class="btn btn-primary">{% bootstrap_icon "home" %}</a>