- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 Flask-login 与以下用户类一起使用。起初我没有覆盖 is_authenticated()
方法,但我认为它可能会解决我的问题(但没有)。
我在 3 台不同的计算机上运行了我的代码。对于其中一个,我必须调用 is_authenticated()
方法作为常规方法(使用 ()
),在另外两个方法上,我必须使用 is_authenticated 作为 bool 值(不使用 ()
)。
在所有计算机中,解释器都设置为 python2.7。
我错过了什么?
class User(UserMixin):
"""
Defines each user.
"""
def __init__(self, user, pwd):
self.username = user
self.password = pwd
def get_id(self):
return self.username
def is_authenticated(self):
return True
这是我调用的方法:
@app.before_request
def before_request():
g.user = flask.ext.login.current_user
g.username = g.user.get_id()
@app.route('/', methods=['GET', 'POST'])
@flask.ext.login.login_required
def index():
if g.user is None or not g.user.is_authenticated(): // or g.user.is_authenticated
return redirect('login')
return render_template('main.html', user=g.username)
最佳答案
像这样吗?检查它是 bool 值还是函数:
if type(is_authenticated) == type(True): # if it's a boolean, this is True.
# Your code
else: # if not, it's a function.
is_authenticated()
# Your code
在这里创建一个函数是一个好主意,如下所示:
def function_name():
if type(is_authenticated) == type(True):
return is_authenticated
else:
return is_authenticated()
关于python - 如何在 Flask-login 中调用 is_authenticated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33274337/
我正在使用 django-email-as-username使用电子邮件而不是用户名进行身份验证的应用程序,它的作用就像一个魅力。 现在,在 查看 我想打电话 if request.user.is_a
我正在我的 views.py 中检查用户是否经过身份验证。然而,Django 不断抛出异常 WSGIRequest 对象没有属性“is_authenticated”。我阅读了 stackoverflo
我正在使用 Flask-Login,我想通过调用 current_user.is_authenticated() 检查用户是否已登录。 我的 Flask 应用程序被组织成蓝图,其中包含一个主要的 __
在我的模板中,我有以下内容: {% if user.is_authenticated %} My Account
我正在尝试编写一个用于在 Django 中注销用户的测试。这是代码:urls.py from django.conf.urls import url from django.contrib impor
我的大部分 View 都需要登录。有没有办法指定所有 View 或 View 子集在继续之前必须让用户 is_authenticated() = True。如果没有,用户被重定向到登录页面? 最佳答案
我正在使用一个测试单元来验证 Flask-Login 的登录。这样做的目的是验证凭据不正确的用户的行为: def test_login_user(self): '''test
我正在查看 this website但似乎无法弄清楚如何做到这一点,因为它不起作用。我需要检查当前站点用户是否已登录(已通过身份验证),并且正在尝试: request.user.is_authenti
我刚刚安装了 django all-auth 模块,我的问题是用户 session 始终为 false。 user.is_authenticated 总是给我 false。我注册并使用我的凭据登录,然
我正在努力解决 is_authenticated返回 True当我没有登录时: u = request.user if u.is_authenticated: raise Exception(
这个问题已经有答案了: Flask-Login raises TypeError: 'bool' object is not callable when trying to override is_a
在我的模板 login.html 中,我有: {% if form.errors %} {% if user.is_authenticated %} Your account does
使用 GAE/Django-nonrel 创建简单的应用程序(我认为问题不是特定于 GAE 或 nonrel 分支,最像 PEBKAC 作为 python/django noob,并且会在基本的 dj
在我的 base.html 中,user.is_authenticated 总是返回 false... 我希望基本模板在“登录和注销”之间切换 帮助将不胜感激 基础.html {%
我正在尝试将模板标签/包含标签合并到网站的侧边栏中。当我输入时,页面的主要部分会正确更新: {% if user.is_authenticated %} Hello {{ user.userna
我只是想运行一个简单的 {% if user.is_authenticated %} 。但它总是返回 False。 这是我所有的文件。 views.py from django.shortcuts i
谁能告诉我为什么在下面的代码中我被重定向到 yahoo.com 而不是 google.com? 网址 urlpatterns = patterns('', (r'^$', initialRequest
我正在学习 Flask Mega-Tutorial,我遇到了这段代码: class User(db.Model): id = db.Column(db.Integer, primary_key
我没有看到使用 @login_required 装饰器和 is_authenticated() 之间的明显区别:不知何故,我认为它们执行类似的检查(虽然不完全)。 假设我的 views.py 中有一个
我有一个奇怪的问题,在我的设置文件中,所有需要为模板中的 user.is_authenticated 使用启用的内容都已启用。 我有以下模板标签代码: from django import templ
我是一名优秀的程序员,十分优秀!