所以我剛剛完成了谷歌應用引擎問候教程。迄今爲止都很好。然後我決定嘗試添加一個新的數據存儲模型,然後將其設置在現有的處理程序中。我添加了一個名爲「content2」的第二個內容字段,然後嘗試將其設置在處理程序的留言簿()中,但它不斷出現。我敢肯定這將是最愚蠢的錯誤,但我很困惑。有任何想法嗎?Google應用引擎教程問題 - 新的數據存儲模型
main.py
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
import os
from google.appengine.ext.webapp import template
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
content2 = db.StringProperty(multiline=True)
class MainPage(webapp.RequestHandler):
def get(self):
greetings_query = Greeting.all().order('-date')
greetings = greetings_query.fetch(1000)
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get('content')
greeting.content2 = self.request.get('content')
greeting.put()
self.redirect('/')
class HelloWorld(webapp.RequestHandler):
def get(self):
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
的index.html
<html>
<body>
{% for greeting in greetings %}
{% if greeting.author %}
<b>{{ greeting.author.nickname }}</b> wrote: Dogs name is: {{ pet.name }}
{% else %}
An anonymous person wrote:
{% endif %}
<blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<a href="{{ url }}">{{ url_linktext }}</a>
</body>
</html>
你得到的錯誤是什麼? – 2009-07-27 07:32:15