Questions tagged [flask-cli]

A command line interface in Flask achieved through a click package integration.

Documentation

22 questions
26
votes
6 answers

Where should I implement flask custom commands (cli)

Creating custom commands in flask needs access to the app, which is generally created in app.py like this: import click from flask import Flask app = Flask(__name__) @app.cli.command("create-user") @click.argument("name") def create_user(name): …
m0etaz
  • 953
  • 1
  • 8
  • 21
14
votes
1 answer

Access Flask app context in CLI command

I want to register a CLI command that's defined in a separate file from the Flask app factory. This command needs access to app.config. However, accessing current_app.config from the command raises RuntimeError: Working outside of application…
George Irimiciuc
  • 4,573
  • 8
  • 44
  • 88
13
votes
1 answer

Run Flask CLI command with PyCharm debugger

I have created a custom CLI command in Flask, that I am able to run via flask my_command in the terminal. I want to run this command using PyCharm's debugger. I created a "Flask server" configuration, and running it with the PyCharm debugger stops…
George Irimiciuc
  • 4,573
  • 8
  • 44
  • 88
9
votes
1 answer

Flask CLI commands and arguments

How do you let a Flask CLI command accept an argument? Flask seems to customise the Click Group object, so this doesn't work: @app.cli.command() @app.cli.argument('email') def user_info(email): ...
Tom
  • 7,269
  • 1
  • 42
  • 69
6
votes
1 answer

flask command Error: No such command ["create_db"]

I want to run some commands from terminal with 'flask' command but it isn't working. The Following is my project structure- FlaskUserAuthentication ├── FlaskUserAuthentication │   ├── API │   │   ├── __init__.py │   │   ├── db_models.py │   │   └──…
6
votes
2 answers

Why do I get the error "A valid Flask application was not obtained from..." when I use the flask cli to run my app?

I try to use the flask cli to start my application, i.e. flask run. I use the FLASK_APP environment variable to point to my application, i.e. export FLASK_APP=package_name.wsgi:app In my wsgi.py file, I create the app with a factory function, i.e.…
Zuabi
  • 1,112
  • 1
  • 13
  • 26
3
votes
1 answer

Flask-CLI can not run application?

I'm developing a REST API, using flask and flask-restful. I am currently having problems with flask-cli, since in the company environment I can not run with the application. What may be the problem? In the enterprise, we use conda environments, for…
vic.py
  • 409
  • 10
  • 22
3
votes
1 answer

How to add MigrateCommand while using flask built in cli?

Earlier while using Manager from flask_script we can add command to Manager like this. from flask_migrate import Migrate, MigrateCommand from flask_script import Manager manager = Manager(app) manager.add_command('db', MigrateCommand) Now in this…
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
3
votes
1 answer

Creating custom 'test' command to run a test suite for a Flask application

We are extending the Flask-cli with some custom commands. The command test is one of them: # run.py: specified by FLASK_APP # This is the Flask application object app = create_app(os.getenv('FLASK_ENV') or 'default') @app.cli.command() def test(): …
Yunus King
  • 1,141
  • 1
  • 11
  • 23
2
votes
2 answers

Flask CLI command not in __init__.py file

I'm trying to add commands to my Flask app. This is my __init__.py file: import os from flask import Flask from flask_cors import CORS from flask_mongoengine import MongoEngine app =…
shlomiLan
  • 659
  • 1
  • 9
  • 33
2
votes
2 answers

Error on Flask-migrate with application factory

run.py db = SQLAlchemy() migrate = Migrate() def create_app(): app = Flask(__name__) db.app = app db.init_app(app) migrate.init_app(app, db) return app if __name__ == '__main__': application = create_app() …
1
vote
1 answer

Error: module 'src' has no attribute 'app.py'

I am trying to import my app from app.py file into my manage.py file. When I run the command python manage.py create_db I get the error: Usage: manage.py create_db [OPTIONS] Try 'manage.py create_db --help' for help. Error: module 'src' has no…
buddy
  • 21
  • 4
0
votes
1 answer

Test flask command when using click.confirm("sometext") with abort option

I want to write a test to the command when the user aborts it, but I have a problem with the abort option in click.confirm when i write full command in console flask questions deleteall i got prompt y/N. When i select N option user cancel command …
DarekD
  • 54
  • 7
0
votes
0 answers

Invoke Flask CLI app from Python command line

I'm pretty new to Python and Flask. I'm trying to execute a Flask app from the command line like : python manage.py run with 'run' being an argument I can change for different functions. My code is this : manage.py import logging from flask.cli…
molko
  • 83
  • 1
  • 10
0
votes
1 answer

How to use flask_cli

How to use FlaskCLi with flask application in a virtualenv I created a folder called app and activated the virtualenv and created an app.py file with the following contents from flask import Flask from flask_cli import FlaskCLI app =…
manuel
  • 23
  • 6
1
2