Skip to content

Fix Flask WebAPP paths to be project-root anchored#30

Closed
arvinder004 wants to merge 2 commits intoEAPD-DRB:mainfrom
arvinder004:fix/flask-paths-cross-platform
Closed

Fix Flask WebAPP paths to be project-root anchored#30
arvinder004 wants to merge 2 commits intoEAPD-DRB:mainfrom
arvinder004:fix/flask-paths-cross-platform

Conversation

@arvinder004
Copy link
Copy Markdown
Contributor

Summary

This PR fixes a bug where the Flask app failed to locate index.html (and other WebAPP assets) when run from the API/ directory due to cwd‑dependent paths in both API/app.py and API/Classes/Base/Config.py. All relevant paths are now anchored to the project root using PROJECT_ROOT and Config.WebAPP_PATH, making template and static file resolution consistent across environments.

Changes

1. Make WebAPP paths project-root anchored in Config.py

File: API/Classes/Base/Config.py

Before (lines 23–29):

UPLOAD_FOLDER = Path('WebAPP')
WebAPP_PATH = Path('WebAPP')
DATA_STORAGE = Path("WebAPP", 'DataStorage')
CLASS_FOLDER = Path("WebAPP", 'Classes')
EXTRACT_FOLDER = Path("")
SOLVERs_FOLDER = Path('WebAPP', 'SOLVERs')

After (lines 23–29):

PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent.parent
UPLOAD_FOLDER = PROJECT_ROOT / 'WebAPP'
WebAPP_PATH = PROJECT_ROOT / 'WebAPP'
DATA_STORAGE = PROJECT_ROOT / 'WebAPP' / 'DataStorage'
CLASS_FOLDER = PROJECT_ROOT / 'WebAPP' / 'Classes'
EXTRACT_FOLDER = PROJECT_ROOT
SOLVERs_FOLDER = PROJECT_ROOT / 'WebAPP' / 'SOLVERs'
  • Introduces PROJECT_ROOT based on __file__, independent of the current working directory.
  • All WebAPP-related paths are now absolute and rooted at the project directory.

2. Configure Flask to use Config.WebAPP_PATH for templates and static files

File: API/App.py

Before:

template_dir = os.path.abspath('WebAPP')
static_dir = os.path.abspath('WebAPP')

app = Flask(
    __name__,
    static_url_path='',
    static_folder=static_dir,
    template_folder=template_dir,
)

After:

from Classes.Base import Config

template_dir = str(Config.WebAPP_PATH.resolve())
static_dir = str(Config.WebAPP_PATH.resolve())

app = Flask(
    __name__,
    static_url_path='',
    static_folder=static_dir,
    template_folder=template_dir,
)
  • Flask now uses the same project-root anchored WebAPP path as defined in Config.py.
  • render_template('index.html') correctly resolves WebAPP/index.html regardless of where the app is launched from.

Related issues

Checklist

  • Paths in Config.py no longer depend on the current working directory.
  • Flask template/static configuration uses Config.WebAPP_PATH.
  • Manual testing from both project root and API/ succeeds.

@SeaCelo
Copy link
Copy Markdown
Collaborator

SeaCelo commented Feb 27, 2026

Thanks @arvinder004. The project-root anchoring pattern you introduced here has been incorporated into the mac-port branch, which applies the same approach across the full codebase.

Closing as superseded. Appreciate the contribution.

@SeaCelo SeaCelo closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Flask cannot find index.html due to cwd‑dependent WebAPP paths

2 participants