2

我正在使用帖子来获取基于用户选择然后提交的单选按钮的参数,并且发生正确的操作,但是随后在页面下方出现了用户未登录的全新页面。我不太确定发生了什么,但这里是适用的代码,我当然使用 HTML 加上带有 python 和 jinja2 的 google appengine。

这里的 HTML:

<form method="POST">
<input type="radio" name="category" value="discussion">Discussion<br>
<input type="radio" name="category" value="adventures">Adventures<br>
<input type="radio" name="category" value="reviews">Reviews<br>
<input type="radio" name="category" value="badges">Badge Applications<br>

<input type="submit" class="btn btn-medium btn-primary" value="Filter!">
</form>

蟒蛇在这里:

def post(self):
    category = self.request.get('category')

    if category:
        user = users.get_current_user()
        logout = users.create_logout_url(self.request.uri)
        global visits

        category = self.request.get('category')                
        posts = db.GqlQuery("select * from Post where category=:1 order by created desc limit 30", category)
        self.render("home.html", posts=posts, user=user, visits=visits, logout=logout)

我的 home.html 文档:

        {% for post in posts %}
            {{post.render() | safe}}
            <br>
        {% endfor %}
4

1 回答 1

0

根据您的问题,我了解到用户未登录,在这种情况下,请尝试以下操作:

def post(self):     
  category = self.request.get('category')      
  if category:         
    user = users.get_current_user()         
    if user:
      logout = users.create_logout_url(self.request.uri)         
      global visits          
      category = self.request.get('category')                         
      posts = db.GqlQuery("select * from Post where category=:1 order by created desc limit 30", category)         
      self.render("home.html", posts=posts, user=user, visits=visits, logout=logout) 
    else:
      self.redirect(users.create_login_url(self.request.uri)) 
于 2012-06-28T05:22:08.377 回答