user391339
user391339

Reputation: 8775

How can I run a flask app from outside the top level directory?

I am working through Miguel Grinberg's Flask Megatutorial (a microblog app), using an Amazon EC2 ubuntu microinstance.

Currently every time I want to start up the flask app I have to cd to the top-level directory ~/microblog/.

Then, I type: flask run -h 0.0.0.0 -p 50000 to start the application.

Is there a way to specify the directory in the commandline so I don't have to keep going to the directory to run the program? There doesn't seem to be but maybe I'm missing something. I'm also pretty new to linux.

~/microblog$ flask run --help
 * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
Usage: flask run [OPTIONS]

  Run a local development server.

  This server is for development purposes only. It does not provide the
  stability, security, or performance of production WSGI servers.

  The reloader and debugger are enabled by default if FLASK_ENV=development
  or FLASK_DEBUG=1.

Options:
  -h, --host TEXT                 The interface to bind to.
  -p, --port INTEGER              The port to bind to.
  --cert PATH                     Specify a certificate file to use HTTPS.
  --key FILE                      The key file to use when specifying a
                                  certificate.
  --reload / --no-reload          Enable or disable the reloader. By default
                                  the reloader is active if debug is enabled.
  --debugger / --no-debugger      Enable or disable the debugger. By default
                                  the debugger is active if debug is enabled.
  --eager-loading / --lazy-loader
                                  Enable or disable eager loading. By default
                                  eager loading is enabled if the reloader is
                                  disabled.
  --with-threads / --without-threads
                                  Enable or disable multithreading.
  --extra-files PATH              Extra files that trigger a reload on change.
                                  Multiple paths are separated by ':'.
  --help                          Show this message and exit.

Upvotes: 4

Views: 7020

Answers (1)

paltaa
paltaa

Reputation: 3244

you can do on Linux

export FLASK_APP=<your_directory>/<your_file> 

on Windows

set FLASK_APP=<your_directory>/<your_file> 

and then run the command, also if you want to export the variable and to be persistent add it to the end of your ~/.bash_profile file with nano, vi or your favorite editor

Flask docs

Upvotes: 7

Related Questions