小编sni*_*ode的帖子

如何解决导入错误:无法从 Flask 中的“flask_login”导入名称“LoginManager”?

我正在尝试https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login的教程。

...
from flask_login import LoginManager

def create_app():
    ...
    db.init_app(app)

    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    from .models import User

    @login_manager.user_loader
    def load_user(user_id):
        # since the user_id is just the primary key of our user table, use it in the query for the user
        return User.query.get(int(user_id))   
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试这样做时,from flask_login import LoginManager 我收到了错误ImportError: cannot import name 'LoginManager' from 'flask_login'

编辑:我已经通过 pip3 在虚拟环境内部和外部安装了flask_login。但是,我无法使用flask_login 中的任何内容。我也尝试过“fromflask_loginimportUserMixin”,并产生了类似的错误。我还通过执行“pip3 list”检查了是否安装了flask_login,并且在此列表中也找到了Flask-Login。

请问我该如何解决这个问题呢?先感谢您!

已解决:我犯了一个愚蠢的错误,没有意识到错误指向另一个目录中的文件。

python flask web flask-login

5
推荐指数
1
解决办法
3162
查看次数

如何解决无法移动到新命名空间:支持 PID 命名空间、支持网络命名空间,但失败:errno = 权限被拒绝?

我正在尝试在 Ubuntu 子系统上安装 Atom 代码编辑器。但是,在执行 sudo apt-get installatom 后,我目前遇到此错误。

这是我当前面临的错误:无法移动到新命名空间:支持 PID 命名空间,支持网络命名空间,但失败:errno = 权限被拒绝。

如下图所示,似乎我必须输入一些内容才能结束命令,但我不知道如何解决它。

在此输入图像描述

请指教。谢谢你!

installation ubuntu atom-editor

5
推荐指数
1
解决办法
5180
查看次数

Elasticsearch 安装问题:系统尚未使用 systemd 作为 init 系统(PID 1)启动。无法操作

我正在关注此网站https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html在我的 Ubuntu 子系统中安装 elasticsearch 以在 Flask 应用程序中使用。

但是,当我尝试执行以下命令时,

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-amd64.deb
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-amd64.deb.sha512
shasum -a 512 -c elasticsearch-7.8.0-amd64.deb.sha512 
sudo dpkg -i elasticsearch-7.8.0-amd64.deb
Run Code Online (Sandbox Code Playgroud)

它返回System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down.

同样,当我关注此页面https://phoenixnap.com/kb/install-elasticsearch-ubuntusudo systemctl start elasticsearch.service时,输入后返回相同的错误。

我对编程很陌生,所以我不太熟悉所有这些错误/警告的含义以及如何解决它。我查了一下,发现systemctl在Windows Ubuntu下不能使用。然而,这些解决方案似乎都不适合我。

我可以就此得到一些建议吗?谢谢你!

windows ubuntu elasticsearch

2
推荐指数
1
解决办法
3038
查看次数