我目前正在使用CS50的Python和JavaScript类进行Web编程。我正在尝试运行Flask服务器,但是却遇到了flask.cli.NoAppException错误。我正在尝试连接到heroku上的postGRES SQL数据库。
import os
from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
app = Flask(__name__)
# Check for environment variable
if not os.getenv("DATABASE_URL"):
raise RuntimeError("DATABASE_URL is not set!!!")
# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
@app.route("/")
def index():
return "Project 1: TODO"
Bash命令提示符:
Stephens-MacBook-Pro:Project1 stephen$ export FLASK_APP=application.py
Stephens-MacBook-Pro:Project1 stephen$ export FLASK_DEBUG=1
Stephens-MacBook-Pro:Project1 stephen$ export DATABASE_URL="postgres://qipeqvvmvvcoqf:1c6aaa3504a58aa2b9be46b85d79a05159f5ccb1f64e3e27070a024a02c3b83e@ec2-174-129-208-118.compute-1.amazonaws.com:5432/d3lrnl0okcg99k"
Stephens-MacBook-Pro:Project1 stephen$ flask run
* Serving Flask app "application.py" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 334-645-143
当我打开http://127.0.0.1:5000/时,应该看到文本“ Project 1:TODO”!
答案 0 :(得分:0)
通常在一个或多个程序包损坏时发生。尝试使用pip更新所有软件包 使用以下命令
pip install -I, --ignore-installed -r requirements.txt