好的,所以这看起来应该很基本,但我就是无法让它工作。我收到一个 404 错误,提示找不到资源,但我被定向到正确的地址,例如 www.url.com/sea?s='1' 用于航行。我有一个具有不同查询参数的链接列表,我希望我的 python 代码对它们进行不同的处理。我正在使用带有 python 和 jinja2 模板系统的谷歌应用程序引擎。
这是我的 HTML:
<h3><a href="/" class="center-it">Quick Navigation</a></h3>
<div class="span1">
<div class="span1">
<h4><a href="/sea">Sea</a></h4>
<ul>
<li><a href="/sea?s='1'">Sailing</a></li>
<li><a href="/sea?s='2'">Diving</a></li>
<li><a href="/sea?s='3'">Surfing</a></li>
<li><a href="/sea?s='4'">Kite Boarding</a></li>
<li><a href="/sea?s='5'">Kayaking</a></li>
</ul>
</div>
这是蟒蛇:
class Sea(BlogHandler):
def get(self, s):
s = self.request.get('s')
if s == '1':
posts = posts = db.GqlQuery("select * from Post where sport=:1 order by created desc limit 30", "sailing")
elif s == '2':
posts = posts = db.GqlQuery("select * from Post where sport=:1 order by created desc limit 30", "diving")
elif s == '3':
posts = posts = db.GqlQuery("select * from Post where sport=:1 order by created desc limit 30", "surfing")
elif s == '4':
posts = posts = db.GqlQuery("select * from Post where sport=:1 order by created desc limit 30", "kiteboarding")
elif s == '5':
posts = posts = db.GqlQuery("select * from Post where sport=:1 order by created desc limit 30", "kayaking")
else:
posts = posts = db.GqlQuery("select * from Post where element=:1 order by created desc limit 30", "sea")
global visits
user = users.get_current_user()
logout = users.create_logout_url(self.request.uri)
self.render('sport.html', user = user, posts=posts, visits = visits, logout=logout)
更新:问题实际上不在于我的 URL 处理的代码。这是对的:
app = webapp2.WSGIApplication([('/', MainPage),
(r'/sea', Sea)]