我想做谷歌應用程序引擎表單驗證,但我不知道如何做到這一點? 我想是這樣的:谷歌App Engine +表單驗證
from google.appengine.ext.db import djangoforms
from django import newforms as forms
class SurveyForm(forms.Form):
occupations_choices = (
('1', ""),
('2', "Undergraduate student"),
('3', "Postgraduate student (MSc)"),
('4', "Postgraduate student (PhD)"),
('5', "Lab assistant"),
('6', "Technician"),
('7', "Lecturer"),
('8', "Other")
)
howreach_choices = (
('1', ""),
('2', "Typed the URL directly"),
('3', "Site is bookmarked"),
('4', "A search engine"),
('5', "A link from another site"),
('6', "From a book"),
('7', "Other")
)
boxes_choices = (
("des", "Website Design"),
("svr", "Web Server Administration"),
("com", "Electronic Commerce"),
("mkt", "Web Marketing/Advertising"),
("edu", "Web-Related Education")
)
name = forms.CharField(label='Name', max_length=100, required=True)
email = forms.EmailField(label='Your Email Address:')
occupations = forms.ChoiceField(choices=occupations_choices, label='What is your occupation?')
howreach = forms.ChoiceField(choices=howreach_choices, label='How did you reach this site?')
# radio buttons 1-5
rating = forms.ChoiceField(choices=range(1,6), label='What is your occupation?', widget=forms.RadioSelect)
boxes = forms.ChoiceField(choices=boxes_choices, label='Are you involved in any of the following? (check all that apply):', widget=forms.CheckboxInput)
comment = forms.CharField(widget=forms.Textarea, required=False)
,我想是這樣顯示的:
template_values = {
'url' : url,
'url_linktext' : url_linktext,
'userName' : userName,
'物品1':SurveyForm() }
而且我有這樣的錯誤消息:
Traceback (most recent call last): File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp_init_.py", line 515, in call handler.get(*groups) File "C:\Program Files\Google\google_appengine\demos\b00213576\main.py", line 144, in get self.response.out.write(template.render(path, template_values)) File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 143, in render return t.render(Context(template_dict)) File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 183, in wrap_render return orig_render(context) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 168, in render return self.nodelist.render(context) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 705, in render bits.append(self.render_node(node, context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 718, in render_node return(node.render(context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template\defaulttags.py", line 209, in render return self.nodelist_true.render(context) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 705, in render bits.append(self.render_node(node, context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 718, in render_node return(node.render(context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 768, in render return self.encode_output(output) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 757, in encode_output return str(output) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\util.py", line 26, in str return self.unicode().encode(settings.DEFAULT_CHARSET) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 73, in unicode return self.as_table() File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 144, in as_table return self._html_output(u'%(label)s%(errors)s%(field)s%(help_text)s', u'%s', '', u'
%s', False) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 129, in _html_output output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text}) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 232, in unicode value = value.str() File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\util.py", line 26, in str return self.unicode().encode(settings.DEFAULT_CHARSET) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\widgets.py", line 246, in unicode return u'\n%s\n
' % u'\n'.join([u'%s ' % w for w in self]) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\widgets.py", line 238, in iter yield RadioInput(self.name, self.value, self.attrs.copy(), choice, i) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\widgets.py", line 212, in init self.choice_value = smart_unicode(choice[0]) TypeError: 'int' object is unsubscriptable
你有什麼想法我可以做這個驗證差異不同的情況?
我曾嘗試使用這種它做的事:
class ItemUserAnswer(djangoforms.ModelForm):
類元: 模型= UserAnswer
但我不知道如何多餘的標籤添加到該表單,並顯示在一條線。 你有什麼建議嗎?
非常感謝,因爲它讓我瘋了,爲什麼現在還沒有工作:/
它應該與其他選擇字段一樣。 – 2010-12-22 17:56:33