0

Since main.app is the default page, regardless of an index.html page in the root directory (GAE does not work like cgi/apache, unfortunately), I've made the form page main.app, and the query/response page response.py. After submitting form, I get error:

Not found error: /response.py did not match any patterns in application configuration.

application: emot13  
version: 1
runtime: python27
api_version: 1
threadsafe: true 

handlers:
-   url: /stylesheets/
    static_dir: stylesheets
-   url: / 
    script: main.app 
-   url: /.
    script: response.app 

main.app:

#!/usr/bin/env python
import cgi
import urllib
from google.appengine.ext import db
import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.out.write("""<html>
<body>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
<body>

    <form action="/response.py" method="post"> #also tried "response.py", no difference
    <p>First Name: <input type="text" name="name"/></p>
    <p>How are things?</p>
    <p><input type="radio" name="mood" value="good">Good</p>
    <p><input type="radio" name="mood" value="bad">Bad</p>
    <p><input type="radio" name="mood" value="fair">Fair</p>
    <p><input type="submit" name="submit" value="Process"/></p>
    </form>
</body></html>""")

app = webapp2.WSGIApplication(
                                    [("/", MainPage)],
                                    debug=True)

def main():
        application.run()

if __name__ == "__main__":
        main()

response.py:

#!/usr/bin/env python
import cgi
import time
import datetime 
import urllib
from google.appengine.ext import db
import webapp2


#model
class Visitor(db.Model):
    name = db.StringProperty(required=1)
    mood = db.StringProperty(choices=["good","bad","fair"])
    date = db.DateTimeProperty(auto_now_add=True)

class Response(webapp2.RequestHandler):
    def get(self):
        today = datetime.date.today()
        self.response.out.write("""<html><head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
<body>
        self.response.out.write(today.strftime(<html><body><p style='color:#3E3535'>%A, %d %B</p>)
</body></html> """)  
        localtime = time.localtime(time.time())
        mon = localtime[1] # MONTH
        h = localtime[3] # HOUR
        name = self.request.get("name")
        name = name.capitalize()
        mood = self.request.get("mood")

        # variables and if/elif statements follow; they all work so that is not the problem.

        responses = db.GqlQuery("SELECT * "
                                "FROM Visitor "
                                "ORDER BY date DESC_LIMIT 1")
        for response in responses:                                                                     
            if mood == "bad" and name != "": 
                # responses follow; they all work so that is not the problem. 

class Process(webapp2.RequestHandler):   
    def post(self):
        name = self.request.get("name")
        mood = self.request.get("mood")
        info = Visitor(name = name, mood = mood)
        info.put()
        self.redirect("/")


app = webapp2.WSGIApplication(
                                    [("/", Response),
                                    ("/", Process)], 
                                    debug=True)

# tried uncommenting this as well v v
#def response():
#    application.run()

#if __name__ == "__response__":
#        response()

Help would be appreciated.

p1nesap
  • 179
  • 1
  • 3
  • 13

1 Answers1

0

The problem is with the 3rd handler, it should read either

-   url: /.*
    script: response.app 

or

-   url: /response.py
    script: response.app 

The code you posted will match against, /a, /b, etc.

Sebastian Kreft
  • 7,819
  • 3
  • 24
  • 41
  • When trying either url /.* or /response.py, I get "404 Not Found The resource could not be found" on response.py, after submitting form. What could be causing this? All my working code is posted above. Form works great using 1 page in app.yaml, but I need query responses to be processed and show on response.py. – p1nesap Jul 04 '12 at 13:06
  • The other problem is that you are defining a get handler in Response, but you are submitting your form using method=POST, so you need a post() method instead in your Response class. – Sebastian Kreft Jul 05 '12 at 17:57