Note that there are some explanatory texts on larger screens.

plurals
  1. POgoogle app engine form validation with css in python
    primarykey
    data
    text
    <p>I have been looking at form validation in python using Django as this seems to be the default way to do it, other than checking each field, performing some validation and kicking out a specific message for each field that is badly formed. Ideally I want the benefits of form validation, but I do not know how to couple this Django way with the .css way I am displaying by form. </p> <p>My form is templated HTML with a css behind to handle the display. The code uses data to send back the form if there is an issue and displays the form which was created previously. So in a nutshell, how do we couple validation to a pre formatted HTML form with css without individually validating.</p> <p>Here is the code I am using:</p> <p>Looking at those references etc <a href="http://www.djangobook.com/en/2.0/chapter07/" rel="nofollow">http://www.djangobook.com/en/2.0/chapter07/</a>, I have been unable to come up with a good way to couple everything together. The problem relates to send back the form and contents if the form is not valid. So what I am doing is pulling out each generated form item by item and displaying in the .html file.</p> <p>So my question is. How do I get this working. Now I can display the form with css style sheet, but I cannot seem to get validation working on the field and I'm always generating an error.</p> <pre><code>class Quote(db.Model): email = db.StringProperty(required=True) class QuoteForm(djangoforms.ModelForm): class Meta: model = Quote exclude = ['entry_time'] class MainPage(webapp.RequestHandler): def get(self): form = QuoteForm(); template_values = {} path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, {'form': form})) def post(self): data = QuoteForm(data=self.request.POST) if data.is_valid(): # save here self.redirect('/Confirm.html') else: template_values = {} path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, {'form': data})) </code></pre> <p>and the part of the .html file is here</p> <pre><code>&lt;div&gt; {{ form.email.errors }} &lt;label for="id_email"&gt;Your e-mail address:&lt;/label&gt; {{ form.email }} &lt;/div&gt; </code></pre> <p>It would nothing that I put into the email field validates correctly. I'm not sure why!? I'm losing the information I have already put into the form. How do I retain this information and actually do proper validation. The model suggests that only a non blank string is required, but nothing ever satisfies the validation.</p> <p>Thanks</p>
    singulars
    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.
 

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