diff --git a/locust/web.py b/locust/web.py index 6c4d54a6b8..c96bd9b59d 100644 --- a/locust/web.py +++ b/locust/web.py @@ -135,11 +135,6 @@ def __init__( # ensures static js files work on Windows mimetypes.add_type("application/javascript", ".js") - if self.web_login: - self.login_manager = LoginManager() - self.login_manager.init_app(app) - self.login_manager.login_view = "login" - if environment.runner: self.update_template_args() if not delayed_start: @@ -518,6 +513,16 @@ def update_user(): return {}, 201 + @property + def login_manager(self): + if self.web_login: + login_manager = LoginManager() + login_manager.init_app(self.app) + login_manager.login_view = "login" + return login_manager + + raise AttributeError("The login_manager is only available with --web-login.\n") + def start(self): self.greenlet = gevent.spawn(self.start_server) self.greenlet.link_exception(greenlet_exception_handler)