Note that there are some explanatory texts on larger screens.

plurals
  1. POGAE + Django Forms + Validation
    primarykey
    data
    text
    <p>I have a problem with how to do validation on GAE. I have read many tutorials and I prepared django form and I wanted to validate it but I dont see eny error messages in my web page code and I dont see any errors when the values are bad. </p> <pre><code>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() </code></pre> <p>Do You know maybe any tutorial - good tutorial how to do it? My index.html:</p> <pre><code> &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;head&gt;&lt;title&gt;Survey&lt;/title&gt; &lt;/head&gt; &lt;body&gt; {% if userName %} You are loged in like: {{ userName }} &lt;a href="{{ url }}"&gt;{{ url_linktext }} &lt;/a&gt; &lt;hr&gt;&lt;br/&gt;&lt;b&gt;Fill in the form: &lt;/b&gt;&lt;br/&gt; &lt;form action="/" method="Post"&gt; {{ form.as_p() }} &lt;input type="submit" name="submit" value="Submit the Form"&gt; &lt;/form&gt; {% else %} Please, log in: &lt;a href="{{ url }}"&gt;{{ url_linktext }}&lt;/a&gt; {% endif %} &lt;/body&gt; &lt;/html&gt; </code></pre> <p>How to do it does the validation started to show me errors? And be like "normal validation"? I thought when I will use the framework it will be much more easier and faster for me but I spent 2 days and it is still not working :/ I could write my own validation in this time :/</p> <p>Can You help me? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload