I have a simple checkmark box on detail.html. When I press the “Send” button, it takes me to results.html. In Django, is it possible to bypass the “Send” button and get directed to results.html when I check and uncheck the checkbox?
Here’s detail.html
{% csrf_token %}
results.html looks like this:
<ul>
{% for choice in poll %}
<li>{{ choice }} </li>
{% endfor %}
</ul>
views.py looks like this:
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 looks like this:
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'),
)
This has nothing to do with Django. You need to write some Javascript that listens to the
onclickevent of the checkbox and changeslocation.hrefaccordingly.