1

像这样进行导入是否合法:

from webapp2_extras.appengine.auth.models import User as webapp2.User

我想将该对象称为 webapp2.User,即使它在技术上不是。这是因为还有其他名为 User 的对象,所以我可能会用这个模型命名用户,比如 webapp2_user ,与 fbuser (通过“使用 facebook 登录”来的 Facebook 用户)和谷歌用户不同。这似乎是一门不错的课程,因为它承认将您的 google 或 facebook 其他帐户与此模型相关联:

class User(object):

    def get_id(self):
        """Returns this user's unique ID, which can be an integer or string."""

    @classmethod
    def get_by_auth_token(cls, user_id, token):
        """Returns a user object based on a user ID and token.

        :param user_id:
            The user_id of the requesting user.
        :param token:
            The token string to be verified.
        :returns:
            A tuple ``(User, timestamp)``, with a user object and
            the token timestamp, or ``(None, None)`` if both were not found.
        """

    @classmethod
    def get_by_auth_password(cls, auth_id, password):
        """Returns a user object, validating password.

        :param auth_id:
            Authentication id.
        :param password:
            Password to be checked.
        :returns:
            A user object, if found and password matches.
        :raises:
            ``auth.InvalidAuthIdError`` or ``auth.InvalidPasswordError``.
        """

    @classmethod
    def create_auth_token(cls, user_id):
        """Creates a new authorization token for a given user ID.

        :param user_id:
            User unique ID.
        :returns:
            A string with the authorization token.
        """

    @classmethod
    def delete_auth_token(cls, user_id, token):
        """Deletes a given authorization token.

        :param user_id:
            User unique ID.
        :param token:
            A string with the authorization token.
        """

感谢您对此的任何回答或评论

4

2 回答 2

2
from webapp2_extras.appengine.auth.models import User as webapp2.User

是无效的语法,python 不允许你有一个你应该使用的.in 。as webapp2.Useras webapp2_User

于 2011-12-17T13:36:04.067 回答
1

这既违法也不推荐。

如果您希望User在不同的应用程序中使用您的基类,您应该继承它并覆盖该应用程序中所需的部分。不要以这种方式导入。

于 2011-12-17T13:42:58.277 回答