如何运行Flask应用程序? [英] How to run a flask application?

查看:267
本文介绍了如何运行Flask应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道启动Flask应用程序的正确方法.该文档显示了两个不同的命令:

I want to know the correct way to start a flask application. The docs show two different commands:

$ flask -a sample run

$ python3.4 sample.py 

产生相同的结果并正确运行该应用程序.

produce the same result and run the application correctly.

两者之间有什么区别,运行Flask应用程序应使用哪些区别?

What is the difference between the two and which should be used to run a Flask application?

推荐答案

flask可执行文件是Flask应用程序的简单命令行运行程序.它是在Flask 0.11中引入的.它替换了 Flask-Script 扩展名以添加命令. 文档描述了如何使用和添加命令.

The flask executable is a simple command line runner for Flask apps. It was introduced in Flask 0.11. It replaces the Flask-Script extension for adding commands. The docs describe how to use and add commands to this.

python sample.py命令运行一个Python文件并设置__name__ == "__main__".如果主块调用app.run(),它将运行开发服务器.调用时,您无权将参数更改为run.

The python sample.py command runs a Python file and sets __name__ == "__main__". If the main block calls app.run(), it will run the development server. You don't have the ability to change the arguments to run when calling it.

这两个命令最终都会启动Werkzeug 开发服务器,顾名思义,它会启动一个简单的HTTP服务器,仅应在开发过程中使用.与app.run()方法相比,您应该更喜欢使用flask run命令.

Both these commands ultimately start the Werkzeug development server, which as the name implies starts a simple HTTP server that should only be used during development. You should prefer using the flask run command over the app.run() method.

这篇关于如何运行Flask应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆