Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Flask js files not loading due to template folder and static folder file structure

So I'm trying to make a website where I'm able to just drag and drop folders containing HTML, js, and CSS files into a "library" directory and have those files served on my flask app. There's one big problem I haven't been able to get over. The problem is that all of these HTML files link to their respective js files using relative paths. For example:

<script src="js/keyboard_input_manager.js"></script>

and these files are 2 folders deep into my (combined) templates/static folder. I could fix this by doing

<script src="library/2048/js/keyboard_input_manager.js"></script>

but that is very tedious, especially when working with so many files.

TLDR: If I were to run my flask app and load a template, it wouldn't load any js or CSS because of relative paths.

Is there any way to go about this without individually changing each path to relate to the templates folder?

Example of my current filesystem:

-FLASK PROJECT
   |->library (templates/static folder)
   |    |->2048
   |       |->index.html, index.css, index.js
   |    |->Game2
   |       |->index.html, index.css, index.js
   |->main.py

What I've Tried:

  • Using Blueprint but I can't create a whole blueprint for every file?
  • Messing with paths of template folder and static folder

Flask Noob - Please let me know if I'm leaving out any helpful information :) Thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!