问题标签 [flask-login]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
332 浏览

python - 加入登录功能后,Jinja 按钮不起作用

当我单击下面的按钮进入 addcontact 页面时,它曾经可以工作。由于我已经在我的网络应用程序中添加了登录信息,因此我似乎无法让按钮工作。如果我只有一个链接,它确实有效。任何想法如何让按钮工作?

0 投票
1 回答
6087 浏览

python - TypeError:“必需”对象不可迭代 Flask WTF Forms

我正在按照http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out--net-29982教程开发我自己的应用程序。

我试图创建一个注册表单,但遇到了这个错误:

我的路线页面是

这是我的 models.py 代码

这是我的 forms.py 代码

谁能解释错误在哪里?

0 投票
0 回答
583 浏览

python-2.7 - Flask-Login: KeyError: 'security' 在尝试调用 login_user 时

我有以下代码在我的 Flask 应用程序上登录用户:

但是,当我尝试登录时,它会引发 KeyError: 'security':

我不知道发生了什么,我想我可能需要修复我的烧瓶配置,但我不知道如何。

0 投票
1 回答
2439 浏览

python - Flask-login request_loader not working?

I'm trying to implement Basic Auth on my Flask application with the Flask-Login extension. Following the documentation i tried an example request loader, but it gives me a 401 Unauthorized error, while the soon to be depreciated header_loader works perfectly, so am i doing something wrong or is there a bug in the request_loader.

I use the following request_loader:

#xA;

My protected view:

#xA;

And my request code:

#xA;

when I run my request code it returns:

#xA;

when I leave out the auth part of my request it returns my protected view. Why is flask not accepting the Basic auth header ?

0 投票
1 回答
1268 浏览

python - 远程服务提供用户信息时如何使用 Flask-Login?

我正在构建一个 Flask 应用程序并开始使用 Flask-Login 进行身份验证。困扰我的是 Flask-Login 为烧瓶处理的每个请求调用 load_user 回调。这是来自https://flask-login.readthedocs.org/en/latest/#how-it-works的示例:

要检索用户,我需要通过 VPN 将会话令牌传递给远程 Web 服务,并且远程 Web 服务会执行 db 查询——这会导致每个 Web 请求都有明显的延迟。我的 load_user 看起来像这样:

似乎我正在颠覆框架。只能从会话中存储/检索用户,那么为什么还要从 Web 服务中获取它呢?这个选项似乎也颠覆了 Flask-Login,但消除了延迟并充分利用了会话。

0 投票
3 回答
24390 浏览

flask - Flask-登录密码重置

我正在使用该flask-login库,但我找不到任何关于如何允许用户通过电子邮件重置密码的好的教程或文档。关于如何做到这一点,我可以查看哪些方向/资源?彻底的谷歌搜索没有发现任何有用的东西。

0 投票
2 回答
2542 浏览

python - (unittest) 测试 Flask-Security:无法通过登录页面

我正在尝试向我的基本应用程序添加测试。访问所有内容都需要登录。

这是我的测试用例类:

我正在运行我的测试,在终端中使用鼻子测试,如下所示:source my_env/bin/activate && nosetests --exe

像这样的基本测试失败:

从输出中,我看到这r.data只是登录页面的 HTML,没有错误(例如,错误的用户名或密码)或警报(“请登录以访问此页面”)。

我在此setUp过程中正在登录,因此test_authenticated_access 应该让我访问/myroute/或重定向到登录页面,并显示闪烁的消息“请登录以访问此页面”。但它没有。

我不知道出了什么问题。我的测试基于我在 Flask 文档和这个应用程序样板中找到的那些

0 投票
2 回答
15143 浏览

python - flask_login 中的 login_required 装饰器未重定向到上一页

我正在使用 flask_login 登录和注销应用程序,但重定向回上一页似乎不起作用。我正在使用 flask.views 和 login_required 作为需要用户登录的视图的装饰器。但是,当我尝试访问需要登录的 /path 时,它会重定向到 /login 而不是 /login?next=/path,这意味着 request.get.args("next") 为 None。

我在蓝图中使用烧瓶视图所需的登录,如下所示:

在一个单独的蓝图中,我正在实施身份验证:

任何熟悉登录所需装饰器的人都可以提供一些建议吗?谢谢!

0 投票
1 回答
368 浏览

python - Flask-login:任何内置的令牌认证?(/hello/world?token=123)

我对将身份验证令牌存储在 cookie 中不感兴趣,因为我希望能够向我的用户发送电子邮件并告诉他们单击包含令牌参数生成的链接。

如果用户有令牌身份验证,允许用户绕过 @login_required 的方法最好放在哪里?

0 投票
2 回答
2942 浏览

python - Overriding flask.g in flask unit test

I'm trying to write some unit tests for my flask app that uses OpenID for authentication. Since it seems like there's no way to log in the test client via OpenID (I asked this question but it hasn't received any responses: Flask OpenID unittest), I was thinking of overriding g.user in my test, so I tried the code snippet from http://flask.pocoo.org/docs/testing/#faking-resources-and-context and it works as expected.

Unfortunately, when using flask-login, g.user is overridden in the before_request wrapper that sets

current_user is anonymous, so my test case is broken. One fix is to execute the before_request wrapper code only when in test mode but it seems lame that you need to add test-specific logic in production code. I've tried messing around with the request context too but g.user still gets overridden eventually. Any ideas for a clean way to solve this?