首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从顶级目录之外运行flask应用程序?

如何从顶级目录之外运行flask应用程序?
EN

Stack Overflow用户
提问于 2019-10-11 03:43:45
回答 1查看 980关注 0票数 0

我正在使用Miguel Grinberg的Flask Megatutorial (一个微博应用程序),使用的是亚马逊EC2 ubuntu微实例。

目前,每次我想要启动flask应用程序时,我都必须cd到顶层目录~/microblog/

然后,我输入:flask run -h 0.0.0.0 -p 50000来启动应用程序。

有没有一种方法可以在命令行中指定目录,这样我就不必一直转到目录来运行程序?似乎没有,但也许我漏掉了什么。我对linux也是个新手。

代码语言:javascript
复制
~/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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-11 05:07:23

你可以做到

代码语言:javascript
复制
export FLASK_APP=<your_directory> 

然后运行该命令,如果您想导出变量并保持持久性,也可以使用nano、vi或您喜欢的编辑器将其添加到~/..bash_profile文件的末尾

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58330083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档