contact form on google app engine
<p>I have a website running on google app engine and would like to include a contact form. 
My app.yaml looks like this:</p>

<pre><code>version: 1  
runtime: python27 
api_version: 1 
threadsafe: true

 handlers:
 - url: /      
   static_files: www/index.html
   upload: www/index.html

 - url: /(.*)      
   static_files: www/\1
   upload: www/(.*)
</code></pre>

<p>which is working fine for the static files, but how can i include the py file for the contact form?</p>

<p>I already tried to run it with this app.yaml file:</p>

<pre><code>version: 1  
runtime: python27 
api_version: 1 
threadsafe: true

libraries:
 - name: jinja2 
   version: latest

 - name: webapp2  
   version: latest

 handlers:
 - url: /      
   static_files: www/index.html
   upload: www/index.html

 - url: /(.*)      
   static_files: www/\1
   upload: www/(.*)

 - url: /.*   
   script: www/contactForm.app
</code></pre>

<p>but it didn't work, e-mail isn't sent 
my py file looks like this:</p>

<pre><code>import webapp2
import jinja2
import os
from google.appengine.api import mail

jinja_environment = jinja2.Environment(autoescape=True,loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')))

class contact(webapp2.RequestHandler):
template = jinja_environment.get_template('contact.html')
def get(self):
self.response.out.write(self.template.render())
def post(self):

# takes input from user
vorname=self.request.get("vorname")
...

message=mail.EmailMessage(sender="authorized sender address",subject="Kontaktformular")

if not mail.is_email_valid(userMail):
  self.response.out.write("Wrong email! Check again!")

message.to="..."
message.body=""" Hallo:
     Vorname: %s
     ...
     Text: %s""" %(vorname,...,text)
message.send()
self.response.out.write("Message sent!")

app = webapp2.WSGIApplication([('/contact',contact)], debug=True)
</code></pre>

<p>Does someone know how to make it work?</p>

<p>Your contact form handler isn't being hit because you have a catch-all rule that precedes it. Also, your contact form handler needs its own URL rather than it too having a catch-all pattern. Try this:</p>

<pre><code>version: 1  
runtime: python27 
api_version: 1 
threadsafe: true

libraries:
- name: jinja2 
  version: latest

- name: webapp2  
  version: latest

handlers:
- url: /      
  static_files: www/index.html
  upload: www/index.html

- url: /contact  
  script: www/contactForm.app

- url: /(.*)      
  static_files: www/\1
  upload: www/(.*)
</code></pre>

<p>Also, your Python appears invalid due to lack of tabs/spaces to indent your code. Should be more like:</p>

<pre><code>import webapp2
import jinja2
import os
from google.appengine.api import mail

jinja_environment = jinja2.Environment(autoescape=True,
                                       loader=jinja2.FileSystemLoader(
                                       os.path.join(os.path.dirname(__file__),
                                                    'templates')))

class contact(webapp2.RequestHandler):
  def get(self):
    template = jinja_environment.get_template('contact.html')
    self.response.out.write(self.template.render())

  def post(self):

    # takes input from user
    vorname=self.request.get("vorname")
    # ...

    if not mail.is_email_valid(userMail):
      self.response.out.write("Wrong email! Check again!")

    message=mail.EmailMessage(sender="authorized sender address",
                              subject="Kontaktformular")

    message.to="..."
    message.body=""" Hallo:
    Vorname: %s
    ...
    Text: %s""" %(vorname,...,text)
    message.send()

    self.response.out.write("Message sent!")

app = webapp2.WSGIApplication([('/contact',contact)], debug=True)
</code></pre>

python google-app-engine web-deployment contact-form