Windows Powershell上的烧瓶 [英] Flask on Windows powershell

查看:56
本文介绍了Windows Powershell上的烧瓶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Flask,并且我正在尝试使用Windows Power Shell运行Flask但我无法这样做

i have installed flask and i am trying to run flask using the windows power shell but i am unable to do so

PS C:\path\to\app> $env:FLASK_APP = "hello.py"

格式已提供文档,我们应该在 $ env 中键入什么?

the format is given the documentation what should we type in $env?

p.s.我能够使用代码在命令提示符下运行flask

p.s. I was able to run flask using command prompt using the code

推荐答案

  • 首先,您必须为 Flask 应用程序激活虚拟环境(我假设您正在使用python的默认虚拟环境模块 venv :py -m venv venv )
    • first, you have to activate the virtual environment for your Flask app (i'm assuming you are using venv the default virtual environment module for python : py -m venv venv)
    • PS C:\myapps\flask\helloflask> .\venv\Scripts\activate
      (venv) PS C:\myapps\flask\helloflask>
      

      • 设置 FLASK_APP 环境变量:
      • (venv) PS C:\myapps\flask\helloflask> $env:FLASK_APP="helloflask:create_app('development')"
        

        请注意用双引号引起来的应用名称"helloflask:create_app('development')" ,否则 Power Shell 会触发红色错误.

        note the double quotes wrapping the app name "helloflask:create_app('development')" otherwise Power Shell triggers a red error.

        在使用 app时,请参考 doc 工厂模式,我会向您推荐读物关于如何运行Flask应用程序

        • 也许您想检查是否已设置 FLASK_APP :
        (venv) PS C:\myapps\flask\helloflask> $env:FLASK_APP
        helloflask:create_app('development')
        

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