0

由于 main.app 是默认页面,不管根目录中的 index.html 页面(不幸的是,GAE 不像 cgi/apache 那样工作),我已经制作了表单页面 main.app,以及查询/响应页面响应.py。提交表单后,我收到错误:

未找到错误:/response.py 与应用程序配置中的任何模式都不匹配。

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 

主应用程序:

#!/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()

响应.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()

帮助将不胜感激。

4

1 回答 1

0

问题出在第三个处理程序上,它应该读取

-   url: /.*
    script: response.app 

或者

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

您发布的代码将匹配 /a、/b 等。

于 2012-07-03T21:32:26.137 回答