On 6/6/07, Vincent Nijs <[EMAIL PROTECTED]> wrote:
>
> I have been searching for examples but everything that I see has a link to a
> database. How to you 'get' the data from a form in django? What is the
> equivalent of 'data = cgi.FieldStorage(keep_blank_values=1)' I would use
> with a Python cgi script?

The form has an attribute called 'cleaned_data', which can be
subscripted using the name of the field. Typos notwithstanding, your
code will end up looking something like:

class MyForm(Form):
    field1 = CharField(max_length=20)
    field2 = BooleanField()

def myview(request):
    if request.method == "POST":
        form = MyForm(request.POST)
        if form.is_valid():
            do_something_with(form.cleaned_data['field1'])
            return HttpResponseRedirect('/some/url')
    else:
        form = MyForm()
    return render_to_response('template.html', { 'form': form })

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to