即使在关闭IDE后也能够访问URL

时间:2017-09-02 16:19:27

标签: python flask

在Flask中开发一个简单的应用程序。即使关闭IDE(PyCharm)后,我也能访问我的URL。此外,我认为因为我以前的代码在端口上持续运行,我的最新代码更改没有得到反映。 我的主机是0.0.0.0,端口是5000。

from cs50.sql import SQL
from flask import Flask, redirect, request, url_for, render_template

app = Flask(__name__)
db = SQL("sqlite:///test.db")

@app.route("/login", methods = ["GET"])
def index():
    return render_template("index.html")

@app.route("/register", methods = ["POST"])
def register():
    if request.form["name"] == "" or request.form["dorm"] == "":
        return render_template("failure.html")
    rows = db.execute("INSERT INTO students (name, dorm) VALUES(:name, :dorm)", name = request.form["name"], dorm = request.form["dorm"])
    return render_template("success.html", registrant = rows)

@app.route("/all", methods = ["GET"])
def seeAllUsers():
    rows = db.execute("SELECT * FROM students")
    return render_template("all_users.html", rows = rows)
if __name__ == "__main__":
    app.run(host="0.0.0.0")

localhost:5000 / login始终在线。其他“GET”网址不是。

2 个答案:

答案 0 :(得分:0)

退出时IDE可能没有关闭正在运行的程序。如果您使用的是Linux或macOS,请使用任务管理器或ps -A查看正在运行的程序。您可能会看到python ...应用程序仍在运行。

答案 1 :(得分:0)

我的问题似乎是我公开竞选(host = 0.0.0.0)。一旦我明确提到主机,它就开始使用

正常工作了
if __name__=="__main__":
    app.run()