首页 > 解决方案 > Heroku 上的 Flask Web 应用程序抛出 Not Found

问题描述

我正在尝试通过 Heroku 部署我的第一个烧瓶网络应用程序。但是当我转到我的应用程序时,它总是显示“未找到 - 在服务器上找不到请求的 URL”。

我尝试了其他路由,例如 /register,但它们都显示“未找到”页面。它在我的 cloud9 IDE 上运行良好,并在 Heroku 上成功部署。

那么问题是什么?提前致谢!

(我正在遵循此说明:http ://cdn.cs50.net/cscip14300/2017/seminars/from_harvard_to_heroku/from_harvard_to_heroku.pdf )

这是我的日志:

2020-05-08T16:14:07.000000+00:00 app[api]: Build started by user eungang3@naver.com
2020-05-08T16:14:31.901041+00:00 heroku[web.1]: Restarting
2020-05-08T16:14:31.914350+00:00 heroku[web.1]: State changed from up to starting
2020-05-08T16:14:30.785786+00:00 app[api]: Deploy 0a1a17fe by user eungang3@naver.com
2020-05-08T16:14:30.785786+00:00 app[api]: Release v22 created by user eungang3@naver.com
2020-05-08T16:14:37.844256+00:00 app[web.1]: * Serving Flask app "application" (lazy loading)
2020-05-08T16:14:37.844285+00:00 app[web.1]: * Environment: production
2020-05-08T16:14:37.844361+00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2020-05-08T16:14:37.844446+00:00 app[web.1]: Use a production WSGI server instead.
2020-05-08T16:14:37.844479+00:00 app[web.1]: * Debug mode: on
2020-05-08T16:14:37.863075+00:00 app[web.1]: INFO:werkzeug: * Running on http://0.0.0.0:50922/ (Press CTRL+C to quit)
2020-05-08T16:14:37.866366+00:00 app[web.1]: INFO:werkzeug: * Restarting with stat
2020-05-08T16:14:38.279279+00:00 heroku[web.1]: State changed from starting to up
2020-05-08T16:14:38.346889+00:00 app[web.1]: WARNING:werkzeug: * Debugger is active!
2020-05-08T16:14:38.365832+00:00 app[web.1]: INFO:werkzeug: * Debugger PIN: 618-739-473
2020-05-08T16:14:40.000000+00:00 app[api]: Build succeeded
2020-05-08T16:15:11.969153+00:00 app[web.1]: INFO:werkzeug:10.186.239.155 - - [08/May/2020 16:15:11] "GET / HTTP/1.1" 404 -
2020-05-08T16:15:11.969938+00:00 heroku[router]: at=info method=GET path="/" host=women-who-read.herokuapp.com request_id=e48ab5b0-3b6b-45d1-84a2-9276d230b941 fwd="182.219.152.173" dyno=web.1 connect=1ms service=5ms status=404 bytes=393 protocol=https

文件结构:

~/
|-final/
 |--static/
  |---fallback.jpg
  |---script.js
  |---style.css
 |--templates/
  |---admin_index.html
  |---admin_search_result.html
  |---index.html
  |---layout.html
  |---login.html
  |---register.html
  |---search_result.html
  |---wishlist.html
 |--application.py
 |--final.db
 |--helpers.py
 |--Procfile
 |--requirements.txt
 |--runtime.txt

application.py(从开始到索引):

import psycopg2
import os

from cs50 import SQL
from flask import Flask, flash, render_template, redirect, url_for, request, session, jsonify
from flask_session import Session
from werkzeug.security import generate_password_hash, check_password_hash
from helpers import login_required, lookup, wrongInput, getISBNList, saveInDB, deleteFromDB, getISBNInDB, getAuthorInDB, saveIn, getBookId, deleteFrom, getBookIdIn, getISBNIn

# Configure application
app = Flask(__name__)

app.secret_key = os.urandom(24)

if __name__ == '__main__':
    port = int(os.environ.get("PORT",8080))
    app.debug = True
    app.run(host="0.0.0.0", port=port)

app.config["TEMPLATES_AUTO_RELOAD"] = True
db = SQL(os.environ.get("DATABASE_URL") or "sqlite:///final.db")

@app.route("/", methods=['GET'])
@login_required
def index():
    authors = getAuthorInDB()

    if request.method == "GET":
        result = getISBNInDB()
        apiResult = []
        currentWish = getBookIdIn("wishlist")
        isItInWish = []

        for isbn in result:
            apiResult.append(lookup(isbn)[0])

            if getBookId(isbn) in currentWish:
                isItInWish.append(True)

            else:
                isItInWish.append(False)

    return render_template("index.html", result=apiResult, authors=authors, isItInWish=isItInWish)

档案:

web: python application.py

运行时.txt

python-3.7.6

要求.txt:

cs50
Flask
Flask-Session
passlib
SQLAlchemy
psycopg2
requests

标签: pythonflaskheroku

解决方案


推荐阅读