Do not use on any
shared computer
August 21, 2008 06:15pm pdt
 
[x]
Attachment Details

Simple Django Forms problem

Tags: Python
Building a simple django app using GAE.   I have a form.  I simply want to take the form data and post it back to the web page as a string.

The problem is that the form doesn't seem to acknowledge my data types.  How do I access my form data on the Python post code?

The form displays fine.  When I enter click 'submit' I get the following error:

------------error--------------
Traceback (most recent call last):
  File "/cygdrive/c/Program Files/Google/google_appengine/google/appengine/ext/webapp/__init__.py", line 501, in __call__
    handler.post(*groups)
  File "/cygdrive/e/appname/test.py", line 154, in post
    results = "results: foo=" + form.foo + ", bar=" + form.bar
AttributeError: 'MyForm' object has no attribute 'foo'
------------end error--------------
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
class MyForm(forms.Form):
  foo = forms.CharField(max_length=25)
  bar = forms.CharField(max_length=25)
 
class AppPage(BaseRequestHandler):
  def get(self):
    self.generate('mypage.html', {
      'page' : 'myPage',
      'myForm': MyForm()
    })
  def post(self):
    form=MyForm(data=self.request.POST)
    # I simply want the form data put into a string I can display.
    # The below line causes an error.
    # The app doesn't think that 'form' has a data element foo.
    # see class MyForm; it clearly has class foo
    # what's the problem here?
    results = "results: foo=" + form.foo + ", bar=" + form.bar
    self.generate('mypage.html', {
      'page' : 'myPage',
      'myForm': MyForm(),
      'results' : results
    })
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: tmonteit
Question Asked On: 07.24.2008
Participating Experts: 1
Points: 500
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by ee_cb
Expert Comment by ee_cb:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ee_cb
Expert Comment by ee_cb:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628