[英]Blank screen error on google app engine
I am trying out this idea where there is a table of 'events' on a '/search' page and when a 'GO' button of an event is pressed, it will increment the 'RSVP' count of that event, and redirect back to '/search'. 我正在尝试这种想法,即在“ /搜索”页面上有一个“事件”表,并且当按下某个事件的“开始”按钮时,它将增加该事件的“ RSVP”计数,并重定向回搜索'。 However, when I clicked on the 'GO' button in my application, it leads to a blank screen with url 'localhost:8080/rsvp'.
但是,当我单击应用程序中的“开始”按钮时,它会导致显示空白页面,并显示网址为“ localhost:8080 / rsvp”。
Finding it strange and wondering which part of my code is wrong. 发现它奇怪并想知道我的代码的哪一部分是错误的。 Here are some of the relevant parts of the code that I think is causing the error.
这是我认为引起错误的代码的一些相关部分。
This is the code from the python file: 这是python文件中的代码:
class RSVPItem(webapp2.RequestHandler):
# increment RSVP count when GO button is clicked
def post(self):
itemkey = ndb.Key('Items', self.request.get('itemid'))
item = itemkey.get()
item.rsvp = item.rsvp + 1
item.put()
self.redirect('/search')
# Handler for the Search page
class Search(webapp2.RequestHandler):
# Display search page
def get(self):
user = users.get_current_user()
if user: # signed in already
# Retrieve items
query = ndb.gql("SELECT * "
"FROM Items ")
template_values = {
'user_mail': users.get_current_user().email(),
'logout': users.create_logout_url(self.request.host_url),
'items': query,
}
template = jinja_environment.get_template('search.html')
self.response.out.write(template.render(template_values))
else:
self.redirect(self.request.host_url)
app = webapp2.WSGIApplication([('/', MainPage),
('/giftbook', MainPageUser),
('/wishlist', WishList),
('/deleteitem', DeleteItem),
('/search', Search),
('/rsvp', RSVPItem),
('/display', Display),
('/displaytag', Displaytag)],
debug=True)
This is from the html file for 'search.html'. 这是来自“ search.html”的html文件。 Only showing the part I think is relevant.
只显示我认为相关的部分。
<h4> Events List </h4>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="10%">Name</th>
<th>Description</th>
<th width = "10%">Link</th>
<th width = "10%">Date</th>
<th width = "10%">Type</th>
<th width = "10%">RSVP</th>
<th width = "10%">Rolling?</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>{{ item.event_name }} </td>
<td>{{ item.description }}</td>
<td>{{ item.event_link}}</td>
<td>{{ item.date.strftime('%Y-%m-%d') }}</td>
<td>{{ item.event_type}}</td>
<td>{{ item.rsvp }}
<td>
<form action="/rsvp" method="post">
<input type="hidden" name="itemid" value="{{ item.item_id }}">
<input type="submit" value="GO!">
</form></td>
</tr>
{% endfor %}
</tbody>
</table>
<form action="/rsvp" method="post">
sends them to /rsvp
. <form action="/rsvp" method="post">
将它们发送到/rsvp
。 Do you have a url handler for /rsvp
? 您是否有
/rsvp
的网址处理程序?
Make sure you cast the Key
to an int
: 确保将
Key
转换为int
:
itemkey = ndb.Key('Items', int(self.request.get('itemid')))
Instead of setting your own id item_id
, just use the built-in Key
: 无需设置自己的ID
item_id
,只需使用内置的Key
:
<input type="hidden" name="itemid" value="{{ item.key.id() }}">
Check the logs to see if there are any errors. 检查日志以查看是否有任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.