Why flask app run but browser is not loading the page?

Viewed 286

I was developing a web application and it was woking fine, then I closed the project and re-opened it after a few hours, the project ran without error, but when I go to localhost:5000 it doesn't even load. I tried the same project in another laptop and it works perfectly. I also tried a simple project in the problematic one like this. The program run, but the browser won't load the page, also here if I use my second laptop it works perfectly. What I should do to fix? Literally like 2 hours ago was working fine

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():  # put application's code here
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

My application code is:


from flask import Flask, render_template
from flask_login import current_user, LoginManager
from DaisPCTO.db import get_user_by_id
from flask_bootstrap import Bootstrap

def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = "qwnfdopqwebnpqepfm"
    Bootstrap(app)
        
    login_manager = LoginManager()
    login_manager.login_view = "auth_blueprint.login"
    login_manager.init_app(app)

    @app.route("/")
    def home():    
        print("hello")             
        return render_template("page.html", user=current_user, roleProf = True if current_user.is_authenticated and current_user.hasRole("Professor") else False)

    @login_manager.user_loader
    def load_user(UserID):
        return get_user_by_id(UserID)

    from DaisPCTO.auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    from DaisPCTO.courses import courses as courses_blueprint 
    app.register_blueprint(courses_blueprint, url_prefix="/courses")

    return app

i'm not putting all the blueprint, this is only the init.py file

1 Answers

In you application you don't run your app you just create a function

if __name__ == '__main__':
    app = create_app()
    app.run()

If you add this to your code you should be abble to see it in http://localhost:5000

Related