LoginManager TypeError: 'NoneType' object is not callable

LoginManager TypeError: 'NoneType' object is not callable

问题

我无法在 Flask 中使用 LoginManager。如果我设置 login_view 它 returns 'NoneType' object is not callable.
我的文件是:

Main Folder>  
    > main.py
    > website >
          > __init__.py
          > views.py
          > models.py
          > static
          > templates

在我的__init__.py

from flask import Flask
from flask_login import LoginManager
from .views import views
from .models import db,User
from flask_mobility import Mobility
from os import path

DB_NAME="database.db"

def create_app():
    app=Flask(__name__)
    Mobility(app)
    
    loginmanager=LoginManager(app)
    loginmanager.login_view('auth.login')

    app.config['SECRET_KEY']='no nothing nobody'
    app.config['SQLALCHEMY_DATABASE_URI']=f'sqlite:///{DB_NAME}'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
    db.init_app(app)
    app.register_blueprint(views, url_prefix='/')
    create_database(app)
    return app

def create_database(app):
    if not path.exists('website/'+DB_NAME):
        db.create_all(app=app)

在我的main.py

from website import create_app

app=create_app()

if __name__=='__main__':
    app.run(host='0.0.0.0',port=80,debug=True)

错误

Traceback (most recent call last):
  File "G:\Python Projects\flask\main.py", line 4, in <module>
    app=create_app()
  File "G:\Python Projects\flask\website\__init__.py", line 14, in create_app
    loginmanager.login_view('auth.login')
TypeError: 'NoneType' object is not callable
[Finished in 2.9s]

我可以看到您的项目中没有 auth 模块。但是,您正在从 auth.

调用 login 函数

如果您是初学者,login_view 是您项目登录页面的视图。如果用户未登录,则 flask 会尝试将用户重定向到该视图。因此,如果您的项目已经有一个登录页面,请将 auth.login 替换为您的登录视图的模块和函数名称。