Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向新用户应用程序引擎显示新消息_Python_Google App Engine_Django Templates - Fatal编程技术网

Python 向新用户应用程序引擎显示新消息

Python 向新用户应用程序引擎显示新消息,python,google-app-engine,django-templates,Python,Google App Engine,Django Templates,我正在使用Google App engine允许用户登录该网站。一旦他们登录,我就为他们创建一个令牌,并使用它来检查用户是否登录。我希望能够向首次用户显示不同的消息,并为返回的用户显示不同的消息 {% ifequal cookie None %} <a href="https://foursquare.com/oauth2/authenticate?client_id=X&response_type=code&redirect_uri=http://

我正在使用Google App engine允许用户登录该网站。一旦他们登录,我就为他们创建一个令牌,并使用它来检查用户是否登录。我希望能够向首次用户显示不同的消息,并为返回的用户显示不同的消息

        {% ifequal cookie None %} 


<a  href="https://foursquare.com/oauth2/authenticate?client_id=X&response_type=code&redirect_uri=http://localhost:8080/">Log In</a>

            <hr></hr>  
        {% else %} 

                        {% for user in set %}
                            {% ifequal user.session_ID access_token %}
                                <a  href="/logout">Logout {{user.user_name}}</a>
                                    <hr></hr>  
                            {% else %}
                            {%endifequal%}
                        {% endfor %}

   <h3 align="center"> 





        {% endifequal %}
{%ifequal cookie None%}

{%else%} {集合%中的用户为%1} {%ifequal user.session_ID access_token%}
{%else%} {%endifequal%} {%endfor%} {%endifequal%}

目前,只有两种选择:登录和不登录。

假设您的用户配置文件实体如下所示:

class UserProfile(db.Model):
    UserID = db.UserProperty()
    FirstSession = db.DateTimeProperty(auto_now_add=True)
试试这个:

from google.appengine.api import users

user = users.get_current_user()

is_existing_user = UserProfile.all().filter('UserID = ', user).get()

if is_existing_user:
    #do something
else:
    #do something else

在这种情况下,我会在user类中使用一个布尔变量:

is_first_time_user = db.BooleanProperty(default=True,verbose_name="is First Time User")

或者模板标记可以使用的用户类中的函数

您指的是第一次使用的用户还是没有活动会话cookie的用户?前者需要您进行某种形式的登录(即用户配置文件实体,该实体保存过去登录您应用程序的用户记录)。@Kevin登录过程分为两步。一旦用户通过了第二个系统的身份验证,就会在数据库中为他们生成一个用户配置文件。我想要一些方法来检查用户是否已经在数据库中,如果他们已经在数据库中,他们不需要通过第二个OAuth进程。在模板中有什么方法可以做到这一点吗?我尝试了以下操作:
check=db.Query(User)check=check.filter(“foursq_auth_token=”,access_token)results=check.fetch(limit=1)if len(results)>0:doRender(self,“index.html”,{“logged_in”:“yes”})
但这似乎不起作用:-(@User082074您不应该在模板中尝试这样做-这不是它的目的。请在代码中执行此操作,并在模板中检查“is_existing_user”。