POST方法执行正确的帖子,然后重新呈现整个页面

时间:2012-06-28 05:08:21

标签: python html google-app-engine navigation jinja2

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

HTML here:

<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>

python here:

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 doc:

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

1 个答案:

答案 0 :(得分: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))