Ich habe ein Problem mit der Validierung von GAE. Ich habe viele Tutorials gelesen und ich bereitete django Form und ich wollte es zu validieren, aber ich sehe nicht eny Fehlermeldungen in meiner Web-Seite-Code und ich sehe keine Fehler, wenn die Werte schlecht sind.
import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext.db import djangoforms
from django import newforms as forms
class SurveyForm(forms.Form):
occupations_choices = (
('0', "Choose one..."),
('1', "Undergraduate student"),
('2', "Postgraduate student (MSc)"),
('3', "Postgraduate student (PhD)"),
('4', "Lab assistant"),
('5', "Technician"),
('6', "Lecturer"),
('7', "Other" )
)
howreach_choices = (
('0', "Choose one..."),
('1', "Typed the URL directly"),
('2', "Site is bookmarked"),
('3', "A search engine"),
('4', "A link from another site"),
('5', "From a book"),
('6', "Other")
)
boxes_choices = (
("des", "Website Design"),
("svr", "Web Server Administration"),
("com", "Electronic Commerce"),
("mkt", "Web Marketing/Advertising"),
("edu", "Web-Related Education")
)
range_choice = (
('1', '1'),
('2', '2'),
('3', '3'),
('4', '4'),
('5', '5')
)
name = forms.CharField(label='Enter your name', max_length=50, 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_choice , label='How would you rate the content of this site?', widget=forms.RadioSelect)
boxes = forms.ChoiceField(choices=boxes_choices, label='Are you involved in any of the following? (check all that apply)', widget=forms.CheckboxSelectMultiple)
comment = forms.CharField(label=('Any other comments?'), widget=forms.Textarea(attrs={'cols': 40, 'rows': 10}), required=False)
class MainHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
userName = user.nickname()
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
userName = ''
template_values = {
'url' : url,
'url_linktext' : url_linktext,
'userName' : userName,
'form' : SurveyForm(),
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
def post(self):
user = users.get_current_user()
if user:
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
userName = user.nickname()
#self.response.out.write(index.html)
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
userName = ''
template_values = {
'url' : url,
'url_linktext' : url_linktext,
'userName' : userName,
'form' : SurveyForm(),
}
form = SurveyForm(self.request.POST)
if self.request.get('submit') == 'Submit the Form':
if form.is_valid():
self.response.out.write("Poprawne dane")
else:
form = SurveyForm()
template_values['form']=form
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
else:
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()
Kennen Sie vielleicht eine Anleitung - eine gute Anleitung, wie man das macht? Mein index.html:
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Survey</title>
</head>
<body>
{% if userName %}
You are loged in like: {{ userName }} <a href="{{ url }}">{{ url_linktext }} </a>
<hr><br/><b>Fill in the form: </b><br/>
<form action="/" method="Post">
{{ form.as_p() }}
<input type="submit" name="submit" value="Submit the Form">
</form>
{% else %}
Please, log in: <a href="{{ url }}">{{ url_linktext }}</a>
{% endif %}
</body>
</html>
Wie kann ich es tun, wenn die Validierung anfängt, mir Fehler anzuzeigen? Und sein wie "normale Validierung"? Ich dachte, wenn ich den Rahmen verwenden wird es viel einfacher und schneller für mich sein, aber ich verbrachte 2 Tage und es ist immer noch nicht funktioniert :/ Ich könnte meine eigene Validierung in dieser Zeit zu schreiben :/
Können Sie mir helfen?