How to get data from forms Horizon Dashboard
Hi,
i'm trying get some data from a form in horizon dashboard. I'm trying to use POST method like a django exemple.
Firstly, i'm want to show in the same view what is on the form, and i'm doing like this.
from django import http
from django.utils.translation import ugettext_lazy as _
from django.views.generic import TemplateView
from django import forms
class AlterForm(forms.Form):
form = forms.CharField(max_length = 20)
class IndexView(TemplateView):
template_name = 'visualizations/validar/index.html'
def get_context_data(request):
if request.method == 'POST':
form = AlterForm(request.POST)
if form.is_valid():
data = form.cleaned_data['form']
return {'form':form,'var':data}
else:
form = AlterForm()
return {'form':form}
and my template is like this
{% block main %}
<form action="" method = "POST"> {% csrf_token %} {{ form.as_p }}
<input type = "submit" value= "OK"/>
</form>
<p> the form text is: {{ var }} </p>
{% endblock %}
the django's examples aren't clear and this code above presents a exception like that: 'IndexView' object has no attribute 'method'
and i have some questions.
1 - As i want to show the text in the same view that the form, i need put something in the action attribute on form tag?
2 - if you note, my get_context_data have as parameter "request", but when i change the code and let "request" as parameter, the form don't appears on view, but when i put "self" as parameter, it do.
3- What i'm doing wrong in the code above and how to fix it?