Hackforge Academy

Category: python

static files css javascript images

Published on 30 Sep 2026

Explanation

Flask serves static files such as CSS, JavaScript, and images from the static directory by default.

Code:

static/
├── css/style.css
├── js/app.js
└── images/logo.png

Explanation

Use url_for() in Jinja2 to generate the correct URL for a static CSS file.

Code:

<link rel="stylesheet"
      href="{{ url_for('static', filename='css/style.css') }}">

Explanation

JavaScript files can be included using the static URL generated by url_for().

Code:

<script src="{{ url_for('static', filename='js/app.js') }}"></script>

Explanation

Images can also be referenced from the static directory using url_for().

Code:

<img src="{{ url_for('static', filename='images/logo.png') }}"
     alt="Logo">

Explanation

Keeping frontend assets in separate folders makes the Flask application easier to maintain.

Code:

static/
├── css/
├── js/
├── images/
└── fonts/

🚀 Learn Spring Boot with real-world projects

💡 Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
⚛️

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
☕

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community