Ask Your Question
0

How to get data from forms Horizon Dashboard

asked 2013-06-17 09:23:43 -0500

Leonardo Afonso gravatar image

updated 2013-06-19 08:06:46 -0500

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-06-20 10:45:43 -0500

armando-migliaccio gravatar image

I would suggest you to redirect your question to the openstack-dev Mailing List, as it will draw attention from a more appropriate audience.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

Stats

Asked: 2013-06-17 09:23:43 -0500

Seen: 251 times

Last updated: Jun 20 '13