我在 detail.html 上有一个简单的复选标记框。当我按下“发送”按钮时,它会将我带到 results.html。在 Django 中,当我选中和取消选中复选框时,是否可以绕过“发送”按钮并定向到 results.html?
这是 detail.html {% csrf_token %}
results.html 看起来像这样:
<ul>
{% for choice in poll %}
<li>{{ choice }} </li>
{% endfor %}
</ul>
view.py 看起来像这样:
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
def handle(request):
artists = {}
if request.method == 'POST':
artists = request.POST.getlist('artists')
return render(request, 'polls/results.html', {'poll': artists})
urls.py 看起来像这样:
from django.conf.urls import patterns, url
from django.conf import settings
urlpatterns = patterns('',
url(r'^detail/$', 'django.views.generic.simple.direct_to_template', {'template': 'polls/detail.html'}),
url(r'^results/$', 'polls.views.handle'),
)