I'm trying to get POST from 2 diferents dropdown, I had get the parametres from the POST, but i get problems with the CSRF token ....
index.html
<form method="post" action="/getdata/">{% csrf_token %}
<select name="Lista">
<option selected="selected" disabled>Objects on page:</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
<select name="Lista2">
<option selected="selected" disabled>Objects on page:</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
<input type="submit" value="Select">
</form>
in spite of I use the csrf token in my html form, it didn't worked ...
views.py
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import render
from view.forms import *
from django.shortcuts import render_to_response, redirect
from view.models import *
def index(request):
if request.method == 'POST':
Lista = request.POST.get('Lista')
print "Lista 1 "+Lista
Lista2 = request.POST.get('Lista2')
print "Lista 2 "+Lista2
#FORMS
form = FormsLista(request.POST)
if form.is_valid():
newPost = Lista(num_lista_1=Lista, num_lista_2=Lista2)
newPost.save()
context = {
'Lista': Lista,
'Lista2': Lista2
}
return render(request, 'showdata.html', context)
else:
template = loader.get_template('index.html')
return HttpResponse(template.render())
models.py
from django.db import models
class Lista (models.Model):
num_lista_1 = models.CharField(max_length=100, null=True)
num_lista_2 = models.CharField(max_length=100, null=True)
def __unicode__(self):
return self.num_lista_1
I have the cookies activated by the way ...