[Python] Flask API returns 404 on CPanel

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I deployed a Flask app on Cpanel (namecheap), the structure is:

    |- home
    |-- cpanel_user
    |---- backend
    |------ src
    |-------- main.py
    |-------- passenger_wsgi.py
    |-------- routes
    |---------- user.py
    |-------- databse
    |---------- app.db
    |-------- static
    |---------- index.html
    |-------- requirements.txt
    |-------- __init__.py

    main.py


    import sys
    # DON'T CHANGE THIS !!!
    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

    from flask import Flask, send_from_directory
    from flask_cors import CORS
    from src.models.user import db
    from src.routes.user import user_bp
    from src.routes.contract import contract_bp

    app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), 'static'))

    application = app

    # Enable CORS for all routes
    CORS(app)

    app.register_blueprint(user_bp, url_prefix='/api')
    app.register_blueprint(contract_bp, url_prefix='/api')

    # uncomment if you need to use database
    app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{os.path.join(os.path.dirname(__file__), 'database', 'app.db')}"

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    # Import all models to ensure they are registered
    from src.models.contract import Contract, Template, ReviewResult

    with app.app_context():
    db.create_all()

    @app.route('/', defaults={'path': ''})
    @app.route('/<path:path>')
    def serve(path):
    static_folder_path = app.static_folder
    if static_folder_path is None:
    return "Static folder not configured", 404

    if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001, debug=True)


    The URL is working fine on cpanel, and loading static/index.html, but when this file calls the api, it returns 404.

    the url is: https://digitin.me/lawaibe/

    any suggestions:

    Continue reading...

Compartilhe esta Página